# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1102780 |
2024-10-18T21:24:53 Z |
Bula |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
514768 KB |
#include <bits/stdc++.h>
using namespace std;
main(){
int tt = 1; cin >> tt;
while(tt--){
int n;
cin >> n;
int c = 1;
vector<int> adj[n + 1];
for(int i = 1; i <= n - 1; i++){
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
if(x != i || y != i + 1) c = 0;
}
vector<int> par(n + 1), d(n + 1);
function<void(int, int)> dfs = [&](int v, int p){
par[v] = p; d[v] = d[p] + 1;
for(auto x : adj[v]){
if(x == p) continue;
dfs(x, v);
}
};
dfs(1, 0);
int q;
cin >> q;
vector<pair<int, int>> A, B;
vector<int> a(q + 1), b(q + 1), g[n + 1], s[n + 1];
for(int i = 1; i <= q; i++){
cin >> a[i] >> b[i];
g[b[i]].push_back(i);
s[a[i]].push_back(i);
A.push_back({a[i], i});
B.push_back({b[i], i});
}
int ok = 1;
if(c == 1){
sort(A.begin(), A.end());
sort(B.begin(), B.end());
for(int i = 0; i < q; i++){
if(A[i].second != B[i].second) ok = 0;
}
}else{
vector<int> G[q + 1], in(q + 1);
for(int i = 1; i <= q; i++){
vector<int> m(q + 1);
int x = a[i], y = b[i];
while(x != y){
if(d[x] < d[y]) swap(x, y);
for(auto u : g[x]){
if(u == i) continue;
G[i].push_back(u);
in[u]++;
m[u]++;
if(m[u] == 2) ok = 0;
}
for(auto u : s[x]){
if(u == i) continue;
G[u].push_back(i);
in[i]++;
m[u]++;
if(m[u] == 2) ok = 0;
}
x = par[x];
}
for(auto u : g[x]){
if(u == i) continue;
G[i].push_back(u);
in[u]++;
m[u]++;
if(m[u] == 2) ok = 0;
}
for(auto u : s[x]){
if(u == i) continue;
G[u].push_back(i);
in[i]++;
m[u]++;
if(m[u] == 2) ok = 0;
}
}
queue<int> Q;
for(int i = 1; i <= q; i++){
if(in[i] == 0) Q.push(i);
}
vector<int> p;
while(!Q.empty()){
int v = Q.front();
Q.pop();
p.push_back(v);
for(auto x : G[v]){
in[x]--;
if(in[x] == 0) Q.push(x);
}
}
if(p.size() != q) ok = 0;
}
cout << (ok ? "Yes" : "No") << '\n';
}
}
Compilation message
jail.cpp:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
4 | main(){
| ^~~~
jail.cpp: In function 'int main()':
jail.cpp:97:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
97 | if(p.size() != q) ok = 0;
| ~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
17 ms |
692 KB |
Output is correct |
5 |
Correct |
37 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
64 ms |
1112 KB |
Output is correct |
10 |
Correct |
62 ms |
18360 KB |
Output is correct |
11 |
Correct |
10 ms |
336 KB |
Output is correct |
12 |
Correct |
45 ms |
452 KB |
Output is correct |
13 |
Correct |
88 ms |
21504 KB |
Output is correct |
14 |
Correct |
87 ms |
21564 KB |
Output is correct |
15 |
Correct |
109 ms |
21612 KB |
Output is correct |
16 |
Correct |
150 ms |
30356 KB |
Output is correct |
17 |
Correct |
105 ms |
24616 KB |
Output is correct |
18 |
Correct |
117 ms |
30300 KB |
Output is correct |
19 |
Correct |
87 ms |
24636 KB |
Output is correct |
20 |
Correct |
90 ms |
24440 KB |
Output is correct |
21 |
Correct |
99 ms |
24636 KB |
Output is correct |
22 |
Correct |
90 ms |
24604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
568 KB |
Output is correct |
16 |
Correct |
3 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
3 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
568 KB |
Output is correct |
16 |
Correct |
3 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
3 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
3 ms |
508 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
3 ms |
500 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
2 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
568 KB |
Output is correct |
16 |
Correct |
3 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
336 KB |
Output is correct |
18 |
Correct |
3 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
3 ms |
508 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
336 KB |
Output is correct |
34 |
Correct |
3 ms |
500 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
2 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
46 ms |
1104 KB |
Output is correct |
39 |
Correct |
66 ms |
17232 KB |
Output is correct |
40 |
Correct |
94 ms |
1636 KB |
Output is correct |
41 |
Correct |
49 ms |
1176 KB |
Output is correct |
42 |
Correct |
75 ms |
1700 KB |
Output is correct |
43 |
Correct |
43 ms |
1104 KB |
Output is correct |
44 |
Correct |
14 ms |
592 KB |
Output is correct |
45 |
Correct |
73 ms |
13520 KB |
Output is correct |
46 |
Correct |
71 ms |
13640 KB |
Output is correct |
47 |
Correct |
103 ms |
13636 KB |
Output is correct |
48 |
Correct |
110 ms |
13644 KB |
Output is correct |
49 |
Correct |
71 ms |
13640 KB |
Output is correct |
50 |
Correct |
67 ms |
13656 KB |
Output is correct |
51 |
Correct |
59 ms |
13388 KB |
Output is correct |
52 |
Correct |
64 ms |
13640 KB |
Output is correct |
53 |
Correct |
14 ms |
1104 KB |
Output is correct |
54 |
Correct |
103 ms |
13512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
11 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Correct |
32 ms |
336 KB |
Output is correct |
14 |
Correct |
52 ms |
336 KB |
Output is correct |
15 |
Correct |
39 ms |
504 KB |
Output is correct |
16 |
Correct |
81 ms |
15176 KB |
Output is correct |
17 |
Correct |
396 ms |
25916 KB |
Output is correct |
18 |
Correct |
1462 ms |
51948 KB |
Output is correct |
19 |
Correct |
112 ms |
16448 KB |
Output is correct |
20 |
Correct |
100 ms |
16448 KB |
Output is correct |
21 |
Correct |
120 ms |
16448 KB |
Output is correct |
22 |
Correct |
340 ms |
26556 KB |
Output is correct |
23 |
Correct |
335 ms |
27048 KB |
Output is correct |
24 |
Correct |
327 ms |
26936 KB |
Output is correct |
25 |
Correct |
324 ms |
27052 KB |
Output is correct |
26 |
Correct |
333 ms |
26936 KB |
Output is correct |
27 |
Correct |
1254 ms |
32508 KB |
Output is correct |
28 |
Correct |
1258 ms |
31844 KB |
Output is correct |
29 |
Correct |
1194 ms |
31872 KB |
Output is correct |
30 |
Correct |
331 ms |
23288 KB |
Output is correct |
31 |
Correct |
311 ms |
22716 KB |
Output is correct |
32 |
Correct |
339 ms |
22888 KB |
Output is correct |
33 |
Correct |
350 ms |
22680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
17 ms |
692 KB |
Output is correct |
5 |
Correct |
37 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
64 ms |
1112 KB |
Output is correct |
10 |
Correct |
62 ms |
18360 KB |
Output is correct |
11 |
Correct |
10 ms |
336 KB |
Output is correct |
12 |
Correct |
45 ms |
452 KB |
Output is correct |
13 |
Correct |
88 ms |
21504 KB |
Output is correct |
14 |
Correct |
87 ms |
21564 KB |
Output is correct |
15 |
Correct |
109 ms |
21612 KB |
Output is correct |
16 |
Correct |
150 ms |
30356 KB |
Output is correct |
17 |
Correct |
105 ms |
24616 KB |
Output is correct |
18 |
Correct |
117 ms |
30300 KB |
Output is correct |
19 |
Correct |
87 ms |
24636 KB |
Output is correct |
20 |
Correct |
90 ms |
24440 KB |
Output is correct |
21 |
Correct |
99 ms |
24636 KB |
Output is correct |
22 |
Correct |
90 ms |
24604 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
4 ms |
336 KB |
Output is correct |
29 |
Correct |
4 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
2 ms |
336 KB |
Output is correct |
32 |
Correct |
4 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
568 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
39 |
Correct |
2 ms |
336 KB |
Output is correct |
40 |
Correct |
3 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
2 ms |
336 KB |
Output is correct |
43 |
Correct |
3 ms |
336 KB |
Output is correct |
44 |
Correct |
2 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
2 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
2 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
3 ms |
508 KB |
Output is correct |
52 |
Correct |
3 ms |
336 KB |
Output is correct |
53 |
Correct |
3 ms |
336 KB |
Output is correct |
54 |
Correct |
3 ms |
336 KB |
Output is correct |
55 |
Correct |
3 ms |
336 KB |
Output is correct |
56 |
Correct |
3 ms |
500 KB |
Output is correct |
57 |
Correct |
4 ms |
336 KB |
Output is correct |
58 |
Correct |
2 ms |
336 KB |
Output is correct |
59 |
Correct |
2 ms |
336 KB |
Output is correct |
60 |
Correct |
46 ms |
1104 KB |
Output is correct |
61 |
Correct |
66 ms |
17232 KB |
Output is correct |
62 |
Correct |
94 ms |
1636 KB |
Output is correct |
63 |
Correct |
49 ms |
1176 KB |
Output is correct |
64 |
Correct |
75 ms |
1700 KB |
Output is correct |
65 |
Correct |
43 ms |
1104 KB |
Output is correct |
66 |
Correct |
14 ms |
592 KB |
Output is correct |
67 |
Correct |
73 ms |
13520 KB |
Output is correct |
68 |
Correct |
71 ms |
13640 KB |
Output is correct |
69 |
Correct |
103 ms |
13636 KB |
Output is correct |
70 |
Correct |
110 ms |
13644 KB |
Output is correct |
71 |
Correct |
71 ms |
13640 KB |
Output is correct |
72 |
Correct |
67 ms |
13656 KB |
Output is correct |
73 |
Correct |
59 ms |
13388 KB |
Output is correct |
74 |
Correct |
64 ms |
13640 KB |
Output is correct |
75 |
Correct |
14 ms |
1104 KB |
Output is correct |
76 |
Correct |
103 ms |
13512 KB |
Output is correct |
77 |
Correct |
1 ms |
336 KB |
Output is correct |
78 |
Correct |
1 ms |
336 KB |
Output is correct |
79 |
Correct |
1 ms |
336 KB |
Output is correct |
80 |
Correct |
1 ms |
336 KB |
Output is correct |
81 |
Correct |
11 ms |
336 KB |
Output is correct |
82 |
Correct |
2 ms |
336 KB |
Output is correct |
83 |
Correct |
1 ms |
336 KB |
Output is correct |
84 |
Correct |
1 ms |
336 KB |
Output is correct |
85 |
Correct |
1 ms |
336 KB |
Output is correct |
86 |
Correct |
1 ms |
336 KB |
Output is correct |
87 |
Correct |
1 ms |
336 KB |
Output is correct |
88 |
Correct |
3 ms |
336 KB |
Output is correct |
89 |
Correct |
32 ms |
336 KB |
Output is correct |
90 |
Correct |
52 ms |
336 KB |
Output is correct |
91 |
Correct |
39 ms |
504 KB |
Output is correct |
92 |
Correct |
81 ms |
15176 KB |
Output is correct |
93 |
Correct |
396 ms |
25916 KB |
Output is correct |
94 |
Correct |
1462 ms |
51948 KB |
Output is correct |
95 |
Correct |
112 ms |
16448 KB |
Output is correct |
96 |
Correct |
100 ms |
16448 KB |
Output is correct |
97 |
Correct |
120 ms |
16448 KB |
Output is correct |
98 |
Correct |
340 ms |
26556 KB |
Output is correct |
99 |
Correct |
335 ms |
27048 KB |
Output is correct |
100 |
Correct |
327 ms |
26936 KB |
Output is correct |
101 |
Correct |
324 ms |
27052 KB |
Output is correct |
102 |
Correct |
333 ms |
26936 KB |
Output is correct |
103 |
Correct |
1254 ms |
32508 KB |
Output is correct |
104 |
Correct |
1258 ms |
31844 KB |
Output is correct |
105 |
Correct |
1194 ms |
31872 KB |
Output is correct |
106 |
Correct |
331 ms |
23288 KB |
Output is correct |
107 |
Correct |
311 ms |
22716 KB |
Output is correct |
108 |
Correct |
339 ms |
22888 KB |
Output is correct |
109 |
Correct |
350 ms |
22680 KB |
Output is correct |
110 |
Correct |
62 ms |
1356 KB |
Output is correct |
111 |
Correct |
34 ms |
1080 KB |
Output is correct |
112 |
Execution timed out |
5105 ms |
514768 KB |
Time limit exceeded |
113 |
Halted |
0 ms |
0 KB |
- |