当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3514:The Writers' Club

题目描述

Forget Facebook, forget Second Life, The Writers’ Club is the next big thing on the Internet. The Writers’ Club is where both writers and lovers of short stories get to meet, publish, read, and discuss the writers’ promising contributions. As any other Internet virtual community, the website gives readers the facility to create a list of their favorite writers. The website maintainers have noticed that readers tend to favor writers already favored by the readers’ favorite writers. For example, if John likes the stories written by Alice, then many of the readers who likes John’s stories also like Alice’s. Needless to say, John’s readers tend to also admire Alice’s favorite writers too.

The website would like to start a recommendation service based on this observation. Continuing with the above example, the website would like to recommend Alice (and her favorite writers, and their favorite writers, and so on) to all of John’s readers. Of course, the recommendation service has to be smart enough not to recommend a writer already favored by the reader receiving the recommendation.

输入解释

Your program will be tested on one or more test cases. The first line of a test case specifies two positive integers: T and N where T is the total number of users (not exceeding 100,000) and N is the number of writers (not exceeding 100). N line follows, one for each writer. Each line is made of one or more names, the first being the name of a writer, and the remaining being the names of admirers of that writer. For example:

writer reader1 reader2readerd

Where writer is the writer’s name, reader1readerd are the names of the writer’s admirers. A name is a sequence of one or more lower-case letters, no longer than 16 characters. Names are unique throughout the test case. Names are separated by one or more spaces.

The last line of the input file is made of two zero’s.

输出解释

For each test case, the first line of the output should be:

--- CASE k

Where k is the test case number (starting at 1), and '-' is the minus sign.

Following that, there should be zero or more lines, one line for each writer being recommended. The format is:

writer reader1 reader2 ...

Where writer is the name of the writer to be recommended for reader1, reader2, and so on. The output lines should be sorted alphabetically according to writers, and for each writer, readers should also be sorted alphabetically. No writer should be recommended for himself. All names in the output are separated by a single space.

输入样例
7 3
john paul ringo
alice paul john
bob  alice sunny cher
5 3
tantawi  taha najeeb
aqqad najeeb ehsan
taha aqqad   najeeb
0 0
输出样例
--- CASE 1
alice ringo
bob john paul ringo
--- CASE 2
taha ehsan
tantawi aqqad ehsan

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3514

最后修改于 2020-10-29T07:03:21+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000 65536