rqnoj-379

来源:互联网 发布:2k16樱木花道脸部数据 编辑:程序博客网 时间:2024/05/18 00:48
#include <iostream>#include <cstdio>#include <string>#include <map>using namespace std;int father[2008];int fatherind_Set(int x){    if(father[x] != x)        father[x] = fatherind_Set(father[x]);    return father[x];}void Union(int x, int y){    x = fatherind_Set(x);    y = fatherind_Set(y);if(x != y)father[x]=y;}int main(){    map<string,int> map;    int n, m, p,i;    cin >> n >> m >> p;    string a,b;    for(i = 1; i <= n; i++)    {        cin >> a;        map[a] = i;        father[i] = i;    }    for(i = 1; i <= m; i++)    {        cin >> a >> b;        Union(map[a],map[b]);    }    for(i = 1; i <= p; i++)    {        cin >> a >> b;        if(fatherind_Set(map[a]) == fatherind_Set(map[b]))            cout << "safe\n";        else            cout << "cc cry\n";    }    return 0;}