# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1102778 |
2024-10-18T21:13:26 Z |
Bula |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
558120 KB |
#include <bits/stdc++.h>
using namespace std;
main(){
int tt = 1; cin >> tt;
while(tt--){
int n;
cin >> n;
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);
}
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<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);
}
int ok = 1;
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:85:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
85 | 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 |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
16 ms |
336 KB |
Output is correct |
5 |
Correct |
38 ms |
1108 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
132 ms |
3928 KB |
Output is correct |
10 |
Correct |
340 ms |
20044 KB |
Output is correct |
11 |
Correct |
11 ms |
340 KB |
Output is correct |
12 |
Correct |
63 ms |
1532 KB |
Output is correct |
13 |
Correct |
317 ms |
53272 KB |
Output is correct |
14 |
Correct |
347 ms |
66696 KB |
Output is correct |
15 |
Execution timed out |
5103 ms |
558120 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
424 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
552 KB |
Output is correct |
13 |
Correct |
2 ms |
340 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 |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
424 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
552 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 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 |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
424 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
552 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
4 ms |
596 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
4 ms |
340 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 |
4 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
424 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
552 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
4 ms |
596 KB |
Output is correct |
30 |
Correct |
4 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
4 ms |
340 KB |
Output is correct |
38 |
Correct |
127 ms |
3984 KB |
Output is correct |
39 |
Correct |
351 ms |
20156 KB |
Output is correct |
40 |
Correct |
81 ms |
2804 KB |
Output is correct |
41 |
Correct |
51 ms |
2124 KB |
Output is correct |
42 |
Correct |
68 ms |
2636 KB |
Output is correct |
43 |
Correct |
42 ms |
2132 KB |
Output is correct |
44 |
Correct |
14 ms |
852 KB |
Output is correct |
45 |
Correct |
63 ms |
14896 KB |
Output is correct |
46 |
Correct |
71 ms |
14964 KB |
Output is correct |
47 |
Correct |
101 ms |
14924 KB |
Output is correct |
48 |
Correct |
104 ms |
14924 KB |
Output is correct |
49 |
Correct |
69 ms |
15040 KB |
Output is correct |
50 |
Correct |
69 ms |
15028 KB |
Output is correct |
51 |
Correct |
57 ms |
14936 KB |
Output is correct |
52 |
Correct |
73 ms |
14924 KB |
Output is correct |
53 |
Correct |
15 ms |
1620 KB |
Output is correct |
54 |
Correct |
70 ms |
15056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 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 |
552 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
34 ms |
824 KB |
Output is correct |
14 |
Correct |
46 ms |
1100 KB |
Output is correct |
15 |
Correct |
40 ms |
1084 KB |
Output is correct |
16 |
Correct |
75 ms |
16460 KB |
Output is correct |
17 |
Correct |
359 ms |
27240 KB |
Output is correct |
18 |
Correct |
1362 ms |
52796 KB |
Output is correct |
19 |
Correct |
102 ms |
17744 KB |
Output is correct |
20 |
Correct |
101 ms |
17752 KB |
Output is correct |
21 |
Correct |
109 ms |
17740 KB |
Output is correct |
22 |
Correct |
385 ms |
27764 KB |
Output is correct |
23 |
Correct |
324 ms |
28020 KB |
Output is correct |
24 |
Correct |
334 ms |
27956 KB |
Output is correct |
25 |
Correct |
376 ms |
28244 KB |
Output is correct |
26 |
Correct |
349 ms |
27996 KB |
Output is correct |
27 |
Correct |
1075 ms |
33512 KB |
Output is correct |
28 |
Correct |
972 ms |
32836 KB |
Output is correct |
29 |
Correct |
988 ms |
32868 KB |
Output is correct |
30 |
Correct |
306 ms |
24232 KB |
Output is correct |
31 |
Correct |
281 ms |
23832 KB |
Output is correct |
32 |
Correct |
322 ms |
24284 KB |
Output is correct |
33 |
Correct |
339 ms |
23816 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 |
0 ms |
336 KB |
Output is correct |
4 |
Correct |
16 ms |
336 KB |
Output is correct |
5 |
Correct |
38 ms |
1108 KB |
Output is correct |
6 |
Correct |
3 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
132 ms |
3928 KB |
Output is correct |
10 |
Correct |
340 ms |
20044 KB |
Output is correct |
11 |
Correct |
11 ms |
340 KB |
Output is correct |
12 |
Correct |
63 ms |
1532 KB |
Output is correct |
13 |
Correct |
317 ms |
53272 KB |
Output is correct |
14 |
Correct |
347 ms |
66696 KB |
Output is correct |
15 |
Execution timed out |
5103 ms |
558120 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |