2018ICPC 北京
A.0:27:15 solved by hl 感人的数据范围,每次连上边之后dfs一下前者看能不能找到自己就行 #include <iostream> #include < string > #include <map> #include <vector> #include <cstdio> using namespace std; int N; const int maxn = 110 ; map < string , int > Hash; vector < int > P[maxn]; bool vis[maxn]; int s; bool dfs( int t){ vis[t] = 1 ; for ( int i = 0 ; i < P[t].size(); i ++ ){ int v = P[t][i]; if (v == s) return false ; if (vis[v]) continue ; if (!dfs(v)) return false ; } return true ; } int main() { while (~scanf( " %d " ,& N)){ int cnt; cnt = 0 ; Hash.clear(); for ( int i = 0 ; i < maxn; i ++ ) P[i].clear(); int flag = 0 ;