Codevs 2639 Dating Program

Source: Internet
Author: User

Title Description Description

CC is a super handsome, eloquence and good, RP very high (this sentence seems to drop RP), but also very humorous, so many mm are very good relations with him. However, the most important thing is that CC can mediate the relationship between each sister very well. The relationship between MM and its complex, CC must strictly grasp the relationship between their friends, so that they go out together, CC if and not a friend of the two mm out to play, the consequences of unimaginable ...
CC only has a few mm relationship, but CC is smarter, he knows A and B are friends, B and C are friends, then A and C are friends.
The following gives m to friends, CC fixed P-date, each date to find two mm, if the two mm is a friend, then will not be out of trouble, the output of ' safe ', to be friends, then CC will inevitably be ..., output ' cc cry '

Enter a description Input Description

The first act n,m,p. n is the number of MM, CC knows m to friend relationship, there is a P-time appointment.
2 to N+1 lines, one string per line, for the first name of the MM. {string length <=11, and all caps}
The following M-line, two strings per line, separated by a space, for the two mm name of a friend relationship.
The following p line, each behavior two strings, separated by a space, for this P-date two mm name.
{Ensure data does not appear without name}

Output description Output Description

Output P line indicates the condition of the first appointment, output ' safe ' or ' cc cry '

Sample input Sample Input

3 1 1
Aaa
Bbb
Ccc
AAA CCC
AAA BBB

Sample output Sample Output

CC Cry

Data range and Tips Data Size & Hint

0<m<=2008
0<p<=2008

Ideas:

map+ and check the set.

Code:
#include <cstdio>#include<map>#include<string>#include<iostream>using namespaceStd;map<string,int>A;stringS,ss;intn,m,p,fa[2001];intFindintx) {    returnx==fa[x]?x:fa[x]=find (Fa[x]);}intMain () {inti,j; scanf ("%d%d%d",&n,&m,&p);  for(i=1; i<=n;i++) Fa[i]=i,cin>>s,a[s]=i;  for(i=1; i<=m;i++) {cin>>s>>SS; intXx=find (A[s]), yy=find (A[ss]); if(fa[xx]!=Fa[yy]) fa[xx]=Fa[yy]; }     for(i=1; i<=p;i++) {cin>>s>>SS; if(Find (a[s]) = =find (A[ss])) printf ("safe\n"); Elseprintf ("cc cry\n"); }    return 0;}

Codevs 2639 Dating Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.