# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
566927 | 2022-05-23T06:29:32 Z | tqbfjotld | Jail (JOI22_jail) | C++14 | 7 ms | 8788 KB |
#include <bits/stdc++.h> using namespace std; vector<int> adjl[120005]; int vis[120005]; int cur; int fs[120005]; int ls[120005]; vector<int> mid[120005]; int A[120005]; int B[120005]; int dfs1(int node, int st, int dest, int p){ if (node==dest){ ls[node] = cur; return 1; } if (st==node){ fs[node] = cur; } for (auto x : adjl[node]){ if (p==x) continue; int res = dfs1(x,st,dest,node); if (res==1&&st!=node){ mid[node].push_back(cur); } if (res==1) return 1; } return 0; } vector<int> adjl2[120005]; bool checkcycle(int node){ if (vis[node]==2) return false; vis[node] = 1; for (auto x : adjl2[node]){ if (vis[x]==1) return true; if (checkcycle(x)) return true; } vis[node] = 2; return false; } int main(){ int Q; scanf("%d",&Q); while (Q--){ int n; scanf("%d",&n); for (int x = 1; x<=n; x++){ adjl[x].clear(); } for (int x = 0; x<n-1; x++){ int a,b; scanf("%d%d",&a,&b); adjl[a].push_back(b); adjl[b].push_back(a); } int m; scanf("%d",&m); for (int x = 0; x<m; x++){ scanf("%d%d",&A[x],&B[x]); } for (int x = 1; x<=n; x++){ fs[x] = -1; ls[x] = -1; mid[x].clear(); } for (cur = 0; cur<m; cur++){ dfs1(A[cur],A[cur],B[cur],-1); } for (int x = 0; x<m; x++){ adjl2[x].clear(); vis[x] = 0; } for (int x = 1; x<=n; x++){ if (fs[x]!=-1){ for (auto y : mid[x]){ adjl2[fs[x]].push_back(y); } } if (ls[x]!=-1){ for (auto y : mid[x]){ adjl2[y].push_back(ls[x]); } } } bool ans = true; for (int x = 0; x<m; x++){ if (checkcycle(x)){ ans = false; } } printf(ans?"Yes\n":"No\n"); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8660 KB | Output is correct |
2 | Correct | 5 ms | 8788 KB | Output is correct |
3 | Incorrect | 7 ms | 8784 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8660 KB | Output is correct |
2 | Incorrect | 4 ms | 8728 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8660 KB | Output is correct |
2 | Incorrect | 4 ms | 8728 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8660 KB | Output is correct |
2 | Incorrect | 4 ms | 8728 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8660 KB | Output is correct |
2 | Incorrect | 4 ms | 8728 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8740 KB | Output is correct |
2 | Incorrect | 4 ms | 8788 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8660 KB | Output is correct |
2 | Correct | 5 ms | 8788 KB | Output is correct |
3 | Incorrect | 7 ms | 8784 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |