# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
566936 | 2022-05-23T06:34:31 Z | tqbfjotld | Jail (JOI22_jail) | C++14 | 5000 ms | 266276 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]); } } if (fs[x]!=-1 && ls[x]!=-1){ adjl2[fs[x]].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 | 8788 KB | Output is correct |
2 | Correct | 7 ms | 8764 KB | Output is correct |
3 | Correct | 5 ms | 8808 KB | Output is correct |
4 | Correct | 16 ms | 8788 KB | Output is correct |
5 | Correct | 27 ms | 8788 KB | Output is correct |
6 | Correct | 6 ms | 8788 KB | Output is correct |
7 | Correct | 6 ms | 8788 KB | Output is correct |
8 | Correct | 8 ms | 8916 KB | Output is correct |
9 | Correct | 361 ms | 23316 KB | Output is correct |
10 | Correct | 2657 ms | 266276 KB | Output is correct |
11 | Correct | 11 ms | 8788 KB | Output is correct |
12 | Correct | 57 ms | 8884 KB | Output is correct |
13 | Execution timed out | 5027 ms | 28124 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8788 KB | Output is correct |
2 | Correct | 6 ms | 8660 KB | Output is correct |
3 | Correct | 6 ms | 8788 KB | Output is correct |
4 | Correct | 8 ms | 8788 KB | Output is correct |
5 | Correct | 6 ms | 8788 KB | Output is correct |
6 | Correct | 5 ms | 8800 KB | Output is correct |
7 | Correct | 5 ms | 8800 KB | Output is correct |
8 | Correct | 5 ms | 8788 KB | Output is correct |
9 | Correct | 5 ms | 8788 KB | Output is correct |
10 | Correct | 7 ms | 8788 KB | Output is correct |
11 | Correct | 5 ms | 8788 KB | Output is correct |
12 | Correct | 5 ms | 8788 KB | Output is correct |
13 | Correct | 6 ms | 8788 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8788 KB | Output is correct |
2 | Correct | 6 ms | 8660 KB | Output is correct |
3 | Correct | 6 ms | 8788 KB | Output is correct |
4 | Correct | 8 ms | 8788 KB | Output is correct |
5 | Correct | 6 ms | 8788 KB | Output is correct |
6 | Correct | 5 ms | 8800 KB | Output is correct |
7 | Correct | 5 ms | 8800 KB | Output is correct |
8 | Correct | 5 ms | 8788 KB | Output is correct |
9 | Correct | 5 ms | 8788 KB | Output is correct |
10 | Correct | 7 ms | 8788 KB | Output is correct |
11 | Correct | 5 ms | 8788 KB | Output is correct |
12 | Correct | 5 ms | 8788 KB | Output is correct |
13 | Correct | 6 ms | 8788 KB | Output is correct |
14 | Correct | 6 ms | 8664 KB | Output is correct |
15 | Correct | 5 ms | 8788 KB | Output is correct |
16 | Correct | 7 ms | 8788 KB | Output is correct |
17 | Correct | 6 ms | 8788 KB | Output is correct |
18 | Correct | 6 ms | 8788 KB | Output is correct |
19 | Correct | 6 ms | 8788 KB | Output is correct |
20 | Correct | 6 ms | 8788 KB | Output is correct |
21 | Correct | 6 ms | 8788 KB | Output is correct |
22 | Correct | 5 ms | 8788 KB | Output is correct |
23 | Correct | 4 ms | 8660 KB | Output is correct |
24 | Correct | 5 ms | 8788 KB | Output is correct |
25 | Correct | 6 ms | 8788 KB | Output is correct |
26 | Correct | 5 ms | 8788 KB | Output is correct |
27 | Correct | 8 ms | 8788 KB | Output is correct |
28 | Correct | 5 ms | 8660 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8788 KB | Output is correct |
2 | Correct | 6 ms | 8660 KB | Output is correct |
3 | Correct | 6 ms | 8788 KB | Output is correct |
4 | Correct | 8 ms | 8788 KB | Output is correct |
5 | Correct | 6 ms | 8788 KB | Output is correct |
6 | Correct | 5 ms | 8800 KB | Output is correct |
7 | Correct | 5 ms | 8800 KB | Output is correct |
8 | Correct | 5 ms | 8788 KB | Output is correct |
9 | Correct | 5 ms | 8788 KB | Output is correct |
10 | Correct | 7 ms | 8788 KB | Output is correct |
11 | Correct | 5 ms | 8788 KB | Output is correct |
12 | Correct | 5 ms | 8788 KB | Output is correct |
13 | Correct | 6 ms | 8788 KB | Output is correct |
14 | Correct | 6 ms | 8664 KB | Output is correct |
15 | Correct | 5 ms | 8788 KB | Output is correct |
16 | Correct | 7 ms | 8788 KB | Output is correct |
17 | Correct | 6 ms | 8788 KB | Output is correct |
18 | Correct | 6 ms | 8788 KB | Output is correct |
19 | Correct | 6 ms | 8788 KB | Output is correct |
20 | Correct | 6 ms | 8788 KB | Output is correct |
21 | Correct | 6 ms | 8788 KB | Output is correct |
22 | Correct | 5 ms | 8788 KB | Output is correct |
23 | Correct | 4 ms | 8660 KB | Output is correct |
24 | Correct | 5 ms | 8788 KB | Output is correct |
25 | Correct | 6 ms | 8788 KB | Output is correct |
26 | Correct | 5 ms | 8788 KB | Output is correct |
27 | Correct | 8 ms | 8788 KB | Output is correct |
28 | Correct | 5 ms | 8660 KB | Output is correct |
29 | Correct | 9 ms | 9004 KB | Output is correct |
30 | Correct | 10 ms | 8788 KB | Output is correct |
31 | Correct | 10 ms | 8892 KB | Output is correct |
32 | Correct | 8 ms | 8788 KB | Output is correct |
33 | Correct | 9 ms | 8788 KB | Output is correct |
34 | Correct | 8 ms | 8808 KB | Output is correct |
35 | Correct | 9 ms | 8876 KB | Output is correct |
36 | Correct | 8 ms | 8788 KB | Output is correct |
37 | Correct | 8 ms | 8744 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8788 KB | Output is correct |
2 | Correct | 6 ms | 8660 KB | Output is correct |
3 | Correct | 6 ms | 8788 KB | Output is correct |
4 | Correct | 8 ms | 8788 KB | Output is correct |
5 | Correct | 6 ms | 8788 KB | Output is correct |
6 | Correct | 5 ms | 8800 KB | Output is correct |
7 | Correct | 5 ms | 8800 KB | Output is correct |
8 | Correct | 5 ms | 8788 KB | Output is correct |
9 | Correct | 5 ms | 8788 KB | Output is correct |
10 | Correct | 7 ms | 8788 KB | Output is correct |
11 | Correct | 5 ms | 8788 KB | Output is correct |
12 | Correct | 5 ms | 8788 KB | Output is correct |
13 | Correct | 6 ms | 8788 KB | Output is correct |
14 | Correct | 6 ms | 8664 KB | Output is correct |
15 | Correct | 5 ms | 8788 KB | Output is correct |
16 | Correct | 7 ms | 8788 KB | Output is correct |
17 | Correct | 6 ms | 8788 KB | Output is correct |
18 | Correct | 6 ms | 8788 KB | Output is correct |
19 | Correct | 6 ms | 8788 KB | Output is correct |
20 | Correct | 6 ms | 8788 KB | Output is correct |
21 | Correct | 6 ms | 8788 KB | Output is correct |
22 | Correct | 5 ms | 8788 KB | Output is correct |
23 | Correct | 4 ms | 8660 KB | Output is correct |
24 | Correct | 5 ms | 8788 KB | Output is correct |
25 | Correct | 6 ms | 8788 KB | Output is correct |
26 | Correct | 5 ms | 8788 KB | Output is correct |
27 | Correct | 8 ms | 8788 KB | Output is correct |
28 | Correct | 5 ms | 8660 KB | Output is correct |
29 | Correct | 9 ms | 9004 KB | Output is correct |
30 | Correct | 10 ms | 8788 KB | Output is correct |
31 | Correct | 10 ms | 8892 KB | Output is correct |
32 | Correct | 8 ms | 8788 KB | Output is correct |
33 | Correct | 9 ms | 8788 KB | Output is correct |
34 | Correct | 8 ms | 8808 KB | Output is correct |
35 | Correct | 9 ms | 8876 KB | Output is correct |
36 | Correct | 8 ms | 8788 KB | Output is correct |
37 | Correct | 8 ms | 8744 KB | Output is correct |
38 | Correct | 311 ms | 23356 KB | Output is correct |
39 | Correct | 2477 ms | 266220 KB | Output is correct |
40 | Correct | 549 ms | 16148 KB | Output is correct |
41 | Correct | 568 ms | 9384 KB | Output is correct |
42 | Correct | 211 ms | 13600 KB | Output is correct |
43 | Correct | 57 ms | 9128 KB | Output is correct |
44 | Correct | 74 ms | 8992 KB | Output is correct |
45 | Correct | 1798 ms | 14148 KB | Output is correct |
46 | Correct | 1654 ms | 14216 KB | Output is correct |
47 | Correct | 830 ms | 66560 KB | Output is correct |
48 | Correct | 830 ms | 67576 KB | Output is correct |
49 | Correct | 1198 ms | 16384 KB | Output is correct |
50 | Correct | 1409 ms | 16628 KB | Output is correct |
51 | Correct | 254 ms | 15040 KB | Output is correct |
52 | Correct | 240 ms | 15136 KB | Output is correct |
53 | Correct | 54 ms | 9228 KB | Output is correct |
54 | Correct | 1489 ms | 13784 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8788 KB | Output is correct |
2 | Correct | 5 ms | 8660 KB | Output is correct |
3 | Correct | 5 ms | 8788 KB | Output is correct |
4 | Correct | 6 ms | 8660 KB | Output is correct |
5 | Correct | 11 ms | 8788 KB | Output is correct |
6 | Correct | 7 ms | 8788 KB | Output is correct |
7 | Correct | 6 ms | 8788 KB | Output is correct |
8 | Correct | 5 ms | 8788 KB | Output is correct |
9 | Correct | 5 ms | 8660 KB | Output is correct |
10 | Correct | 5 ms | 8788 KB | Output is correct |
11 | Correct | 5 ms | 8660 KB | Output is correct |
12 | Correct | 7 ms | 8788 KB | Output is correct |
13 | Correct | 33 ms | 8880 KB | Output is correct |
14 | Correct | 45 ms | 8808 KB | Output is correct |
15 | Correct | 42 ms | 8796 KB | Output is correct |
16 | Execution timed out | 5033 ms | 14324 KB | Time limit exceeded |
17 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8788 KB | Output is correct |
2 | Correct | 7 ms | 8764 KB | Output is correct |
3 | Correct | 5 ms | 8808 KB | Output is correct |
4 | Correct | 16 ms | 8788 KB | Output is correct |
5 | Correct | 27 ms | 8788 KB | Output is correct |
6 | Correct | 6 ms | 8788 KB | Output is correct |
7 | Correct | 6 ms | 8788 KB | Output is correct |
8 | Correct | 8 ms | 8916 KB | Output is correct |
9 | Correct | 361 ms | 23316 KB | Output is correct |
10 | Correct | 2657 ms | 266276 KB | Output is correct |
11 | Correct | 11 ms | 8788 KB | Output is correct |
12 | Correct | 57 ms | 8884 KB | Output is correct |
13 | Execution timed out | 5027 ms | 28124 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |