# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
553021 | 2022-04-24T13:03:01 Z | tht2005 | Jail (JOI22_jail) | C++17 | 5000 ms | 33124 KB |
#include <bits/stdc++.h> using namespace std; const int N = 120005; int n, m, cnt, s[N], t[N], in[N]; vector<int> aj[N], ej[N], S[N], T[N]; queue<int> q; bool dfs(int v, int p_, int t, int i) { bool ok = (v == t); for(int u : aj[v]) { if(ok) break; if(u == p_) continue; ok |= dfs(u, v, t, i); } if(ok) { for(int j : S[v]) { if(i != j) { ej[j].push_back(i); } } for(int j : T[v]) { if(i != j) { ej[i].push_back(j); } } } return ok; } int main() { int _; scanf("%d", &_); while(_--) { scanf("%d", &n); for(int i = 1; i < n; ++i) { int u, v; scanf("%d %d", &u, &v); aj[u].push_back(v); aj[v].push_back(u); } scanf("%d", &m); for(int i = 1; i <= m; ++i) { scanf("%d %d", s + i, t + i); S[s[i]].push_back(i); T[t[i]].push_back(i); } for(int i = 1; i <= m; ++i) { dfs(s[i], -1, t[i], i); } for(int i = 1; i <= m; ++i) { for(int j : ej[i]) { ++in[j]; } } for(int i = 1; i <= m; ++i) { if(in[i] == 0) { q.push(i); } } cnt = 0; while(!q.empty()) { int v = q.front(); q.pop(); ++cnt; for(int u : ej[v]) { if((--in[u]) == 0) { q.push(u); } } } for(int i = 1; i <= n; ++i) { aj[i].clear(); ej[i].clear(); S[i].clear(); T[i].clear(); in[i] = 0; } puts((cnt == m) ? "Yes" : "No"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11476 KB | Output is correct |
2 | Correct | 6 ms | 11476 KB | Output is correct |
3 | Correct | 6 ms | 11476 KB | Output is correct |
4 | Correct | 18 ms | 11716 KB | Output is correct |
5 | Correct | 32 ms | 11624 KB | Output is correct |
6 | Correct | 7 ms | 11600 KB | Output is correct |
7 | Correct | 8 ms | 11604 KB | Output is correct |
8 | Correct | 10 ms | 11604 KB | Output is correct |
9 | Correct | 288 ms | 15560 KB | Output is correct |
10 | Correct | 1894 ms | 29144 KB | Output is correct |
11 | Correct | 13 ms | 11732 KB | Output is correct |
12 | Correct | 64 ms | 12608 KB | Output is correct |
13 | Execution timed out | 5016 ms | 33124 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11476 KB | Output is correct |
2 | Correct | 8 ms | 11476 KB | Output is correct |
3 | Correct | 8 ms | 11556 KB | Output is correct |
4 | Correct | 12 ms | 11628 KB | Output is correct |
5 | Correct | 7 ms | 11592 KB | Output is correct |
6 | Correct | 7 ms | 11636 KB | Output is correct |
7 | Correct | 7 ms | 11604 KB | Output is correct |
8 | Correct | 8 ms | 11592 KB | Output is correct |
9 | Correct | 8 ms | 11604 KB | Output is correct |
10 | Correct | 7 ms | 11604 KB | Output is correct |
11 | Correct | 8 ms | 11620 KB | Output is correct |
12 | Correct | 9 ms | 11548 KB | Output is correct |
13 | Correct | 6 ms | 11604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11476 KB | Output is correct |
2 | Correct | 8 ms | 11476 KB | Output is correct |
3 | Correct | 8 ms | 11556 KB | Output is correct |
4 | Correct | 12 ms | 11628 KB | Output is correct |
5 | Correct | 7 ms | 11592 KB | Output is correct |
6 | Correct | 7 ms | 11636 KB | Output is correct |
7 | Correct | 7 ms | 11604 KB | Output is correct |
8 | Correct | 8 ms | 11592 KB | Output is correct |
9 | Correct | 8 ms | 11604 KB | Output is correct |
10 | Correct | 7 ms | 11604 KB | Output is correct |
11 | Correct | 8 ms | 11620 KB | Output is correct |
12 | Correct | 9 ms | 11548 KB | Output is correct |
13 | Correct | 6 ms | 11604 KB | Output is correct |
14 | Correct | 6 ms | 11576 KB | Output is correct |
15 | Correct | 8 ms | 11476 KB | Output is correct |
16 | Correct | 10 ms | 11604 KB | Output is correct |
17 | Correct | 8 ms | 11616 KB | Output is correct |
18 | Correct | 8 ms | 11640 KB | Output is correct |
19 | Correct | 6 ms | 11476 KB | Output is correct |
20 | Correct | 10 ms | 11640 KB | Output is correct |
21 | Correct | 8 ms | 11572 KB | Output is correct |
22 | Correct | 8 ms | 11604 KB | Output is correct |
23 | Correct | 7 ms | 11596 KB | Output is correct |
24 | Correct | 8 ms | 11596 KB | Output is correct |
25 | Correct | 8 ms | 11604 KB | Output is correct |
26 | Correct | 7 ms | 11604 KB | Output is correct |
27 | Correct | 8 ms | 11604 KB | Output is correct |
28 | Correct | 7 ms | 11524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11476 KB | Output is correct |
2 | Correct | 8 ms | 11476 KB | Output is correct |
3 | Correct | 8 ms | 11556 KB | Output is correct |
4 | Correct | 12 ms | 11628 KB | Output is correct |
5 | Correct | 7 ms | 11592 KB | Output is correct |
6 | Correct | 7 ms | 11636 KB | Output is correct |
7 | Correct | 7 ms | 11604 KB | Output is correct |
8 | Correct | 8 ms | 11592 KB | Output is correct |
9 | Correct | 8 ms | 11604 KB | Output is correct |
10 | Correct | 7 ms | 11604 KB | Output is correct |
11 | Correct | 8 ms | 11620 KB | Output is correct |
12 | Correct | 9 ms | 11548 KB | Output is correct |
13 | Correct | 6 ms | 11604 KB | Output is correct |
14 | Correct | 6 ms | 11576 KB | Output is correct |
15 | Correct | 8 ms | 11476 KB | Output is correct |
16 | Correct | 10 ms | 11604 KB | Output is correct |
17 | Correct | 8 ms | 11616 KB | Output is correct |
18 | Correct | 8 ms | 11640 KB | Output is correct |
19 | Correct | 6 ms | 11476 KB | Output is correct |
20 | Correct | 10 ms | 11640 KB | Output is correct |
21 | Correct | 8 ms | 11572 KB | Output is correct |
22 | Correct | 8 ms | 11604 KB | Output is correct |
23 | Correct | 7 ms | 11596 KB | Output is correct |
24 | Correct | 8 ms | 11596 KB | Output is correct |
25 | Correct | 8 ms | 11604 KB | Output is correct |
26 | Correct | 7 ms | 11604 KB | Output is correct |
27 | Correct | 8 ms | 11604 KB | Output is correct |
28 | Correct | 7 ms | 11524 KB | Output is correct |
29 | Correct | 11 ms | 11732 KB | Output is correct |
30 | Correct | 10 ms | 11604 KB | Output is correct |
31 | Correct | 12 ms | 11692 KB | Output is correct |
32 | Correct | 9 ms | 11520 KB | Output is correct |
33 | Correct | 9 ms | 11620 KB | Output is correct |
34 | Correct | 10 ms | 11592 KB | Output is correct |
35 | Correct | 11 ms | 11608 KB | Output is correct |
36 | Correct | 9 ms | 11628 KB | Output is correct |
37 | Correct | 11 ms | 11604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11476 KB | Output is correct |
2 | Correct | 8 ms | 11476 KB | Output is correct |
3 | Correct | 8 ms | 11556 KB | Output is correct |
4 | Correct | 12 ms | 11628 KB | Output is correct |
5 | Correct | 7 ms | 11592 KB | Output is correct |
6 | Correct | 7 ms | 11636 KB | Output is correct |
7 | Correct | 7 ms | 11604 KB | Output is correct |
8 | Correct | 8 ms | 11592 KB | Output is correct |
9 | Correct | 8 ms | 11604 KB | Output is correct |
10 | Correct | 7 ms | 11604 KB | Output is correct |
11 | Correct | 8 ms | 11620 KB | Output is correct |
12 | Correct | 9 ms | 11548 KB | Output is correct |
13 | Correct | 6 ms | 11604 KB | Output is correct |
14 | Correct | 6 ms | 11576 KB | Output is correct |
15 | Correct | 8 ms | 11476 KB | Output is correct |
16 | Correct | 10 ms | 11604 KB | Output is correct |
17 | Correct | 8 ms | 11616 KB | Output is correct |
18 | Correct | 8 ms | 11640 KB | Output is correct |
19 | Correct | 6 ms | 11476 KB | Output is correct |
20 | Correct | 10 ms | 11640 KB | Output is correct |
21 | Correct | 8 ms | 11572 KB | Output is correct |
22 | Correct | 8 ms | 11604 KB | Output is correct |
23 | Correct | 7 ms | 11596 KB | Output is correct |
24 | Correct | 8 ms | 11596 KB | Output is correct |
25 | Correct | 8 ms | 11604 KB | Output is correct |
26 | Correct | 7 ms | 11604 KB | Output is correct |
27 | Correct | 8 ms | 11604 KB | Output is correct |
28 | Correct | 7 ms | 11524 KB | Output is correct |
29 | Correct | 11 ms | 11732 KB | Output is correct |
30 | Correct | 10 ms | 11604 KB | Output is correct |
31 | Correct | 12 ms | 11692 KB | Output is correct |
32 | Correct | 9 ms | 11520 KB | Output is correct |
33 | Correct | 9 ms | 11620 KB | Output is correct |
34 | Correct | 10 ms | 11592 KB | Output is correct |
35 | Correct | 11 ms | 11608 KB | Output is correct |
36 | Correct | 9 ms | 11628 KB | Output is correct |
37 | Correct | 11 ms | 11604 KB | Output is correct |
38 | Correct | 339 ms | 15084 KB | Output is correct |
39 | Correct | 1912 ms | 29332 KB | Output is correct |
40 | Correct | 586 ms | 14656 KB | Output is correct |
41 | Correct | 575 ms | 13076 KB | Output is correct |
42 | Correct | 242 ms | 14688 KB | Output is correct |
43 | Correct | 59 ms | 13072 KB | Output is correct |
44 | Correct | 75 ms | 11952 KB | Output is correct |
45 | Correct | 1616 ms | 17204 KB | Output is correct |
46 | Correct | 1566 ms | 17196 KB | Output is correct |
47 | Correct | 753 ms | 22732 KB | Output is correct |
48 | Correct | 722 ms | 22848 KB | Output is correct |
49 | Correct | 1240 ms | 17460 KB | Output is correct |
50 | Correct | 1057 ms | 17304 KB | Output is correct |
51 | Correct | 260 ms | 17976 KB | Output is correct |
52 | Correct | 237 ms | 18772 KB | Output is correct |
53 | Correct | 74 ms | 11980 KB | Output is correct |
54 | Correct | 1394 ms | 17132 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11476 KB | Output is correct |
2 | Correct | 6 ms | 11584 KB | Output is correct |
3 | Correct | 6 ms | 11476 KB | Output is correct |
4 | Correct | 6 ms | 11476 KB | Output is correct |
5 | Correct | 14 ms | 11624 KB | Output is correct |
6 | Correct | 6 ms | 11604 KB | Output is correct |
7 | Correct | 6 ms | 11476 KB | Output is correct |
8 | Correct | 7 ms | 11516 KB | Output is correct |
9 | Correct | 7 ms | 11476 KB | Output is correct |
10 | Correct | 6 ms | 11604 KB | Output is correct |
11 | Correct | 6 ms | 11476 KB | Output is correct |
12 | Correct | 9 ms | 11604 KB | Output is correct |
13 | Correct | 37 ms | 11980 KB | Output is correct |
14 | Correct | 51 ms | 12372 KB | Output is correct |
15 | Correct | 49 ms | 12172 KB | Output is correct |
16 | Execution timed out | 5022 ms | 17480 KB | Time limit exceeded |
17 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11476 KB | Output is correct |
2 | Correct | 6 ms | 11476 KB | Output is correct |
3 | Correct | 6 ms | 11476 KB | Output is correct |
4 | Correct | 18 ms | 11716 KB | Output is correct |
5 | Correct | 32 ms | 11624 KB | Output is correct |
6 | Correct | 7 ms | 11600 KB | Output is correct |
7 | Correct | 8 ms | 11604 KB | Output is correct |
8 | Correct | 10 ms | 11604 KB | Output is correct |
9 | Correct | 288 ms | 15560 KB | Output is correct |
10 | Correct | 1894 ms | 29144 KB | Output is correct |
11 | Correct | 13 ms | 11732 KB | Output is correct |
12 | Correct | 64 ms | 12608 KB | Output is correct |
13 | Execution timed out | 5016 ms | 33124 KB | Time limit exceeded |
14 | Halted | 0 ms | 0 KB | - |