// 2004国内予選F : Name the Crossing #include #include #include using namespace std; int c[200][200]; // 同水準の通りをチェック bool check(int A, int B, int size){ bool flag = false; for(int i=0;i> n, n){ // グラフ(隣接行列)の初期化 for(int i=0;i<200;i++) for(int j=0;j<200;j++) c[i][j] = 1000000; // 通りの名前と番号を対応付けるmap map mp; int size = 0; for(int i=0;i> name; int pos = name.find("-"); string A = name.substr(0,pos); string B = name.substr(pos+1); if(!mp.count(A)) mp[A] = size++; if(!mp.count(B)) mp[B] = size++; // AとBは違う方向の通り c[mp[A]][mp[B]] = 1; } // 同水準な通りをチェック for(int i=0;i> m; for(int i=0;i> name; int pos = name.find("-"); string A = name.substr(0,pos); string B = name.substr(pos+1); // 構築したグラフ上で,A-Bへのパスが存在し, // パスの長さが奇数(異なる方向の通り)ならYES if(mp.count(A)&&mp.count(B)&&c[mp[A]][mp[B]]%2==1) puts("YES"); else puts("NO"); } } }