# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
725000 |
2023-04-16T12:30:26 Z |
berr |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
30288 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2e4 + 37;
vector<int> adj[N], adj2[N], adj3[N], s(N), e(N), ti(N), to(N), vis(N), de(N);
int par[N][18], cnt, flag;
bool ia(int x, int y){
return ti[x] <= ti[y] && to[x] >= to[y];
}
int d(int x, int y){
if(x == y) return 0;
int sum = 0;
if(ia(x, y)) swap(x, y);
for (int i = 17; i >= 0; i--){
if(!ia(par[x][i], y)){
x = par[x][i];
sum += 1<<i;
}
}
sum++;
x=par[x][0];
swap(x, y);
sum+=de[x]-de[y];
return sum;
}
bool c(int x, int y){
if( (d(s[x], e[x]) == (d(s[x], e[y])+ d(e[y], e[x])))) return 1;
swap(x, y);
return (d(s[x], e[x]) == (d(s[x], s[y])+ d(s[y], e[x])));
}
bool c2(int x, int y){
if(d(s[x], e[x]) == d(s[x], s[y])+ d(s[y], e[y]) + d(e[y], e[x])) return 1;
if(d(s[x], e[x]) == d(s[x], e[y])+ d(e[y], s[y]) + d(s[y], e[x])) return 1;
return 0;
}
void dfs(int v, int p){
par[v][0] = p;
de[v]=de[p]+1;
ti[v] = cnt++;
for (auto i: adj[v]){
if (i == p) continue;
dfs(i, v);
}
to[v] = cnt++;
}
void dfs2(int v, int z){
vis[v] = z;
for (auto i: adj2[v]){
if (vis[i]==z) flag = 0;
else if(vis[i]<z) dfs2(i, z);
}
vis[v]=z+1;
}
void solve(){
int n; cin >> n;
cnt = 0;
for (int i = 1; i < n; i++){
int x, y; cin >> x >> y;
x--; y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
de[0]=-1;
dfs(0, 0);
for (int i = 1; i < 18; i++){
for(int l = 0; l < n; l++){
par[l][i] = par[par[l][i-1]][i-1];
}
}
flag = 1;
int m; cin >> m;
for (int i = 0; i < m; i++){
cin >> s[i] >> e[i];
s[i]--; e[i]--;
}
for (int i = 0; i < m; i++){
for (int l = i+1; l < m; l++){
if (c(i, l)) adj2[i].push_back(l);
if (c(l, i)) adj2[l].push_back(i);
if(c2(i, l)) flag = 0;
if(c2(l, i)) flag = 0;
}
}
for(int i = 0; i < n; i++){
if(vis[i]==0) dfs2(i, n*i+1);
}
if(flag) cout << "Yes\n";
else cout << "No\n";
for (int i = 0; i < n; i++){
adj[i].clear();
adj2[i].clear();
vis[i] = 0;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t; cin>>t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11604 KB |
Output is correct |
2 |
Correct |
6 ms |
11604 KB |
Output is correct |
3 |
Correct |
6 ms |
11604 KB |
Output is correct |
4 |
Correct |
17 ms |
11604 KB |
Output is correct |
5 |
Correct |
39 ms |
11604 KB |
Output is correct |
6 |
Correct |
6 ms |
11604 KB |
Output is correct |
7 |
Correct |
7 ms |
11604 KB |
Output is correct |
8 |
Correct |
136 ms |
11604 KB |
Output is correct |
9 |
Correct |
4797 ms |
13848 KB |
Output is correct |
10 |
Correct |
254 ms |
30184 KB |
Output is correct |
11 |
Correct |
45 ms |
11628 KB |
Output is correct |
12 |
Correct |
1577 ms |
11708 KB |
Output is correct |
13 |
Execution timed out |
5029 ms |
29344 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11604 KB |
Output is correct |
2 |
Correct |
6 ms |
11604 KB |
Output is correct |
3 |
Correct |
7 ms |
11604 KB |
Output is correct |
4 |
Correct |
7 ms |
11604 KB |
Output is correct |
5 |
Correct |
17 ms |
11572 KB |
Output is correct |
6 |
Correct |
8 ms |
11640 KB |
Output is correct |
7 |
Correct |
9 ms |
11604 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
7 ms |
11604 KB |
Output is correct |
10 |
Correct |
7 ms |
11604 KB |
Output is correct |
11 |
Correct |
8 ms |
11648 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
7 ms |
11604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11604 KB |
Output is correct |
2 |
Correct |
6 ms |
11604 KB |
Output is correct |
3 |
Correct |
7 ms |
11604 KB |
Output is correct |
4 |
Correct |
7 ms |
11604 KB |
Output is correct |
5 |
Correct |
17 ms |
11572 KB |
Output is correct |
6 |
Correct |
8 ms |
11640 KB |
Output is correct |
7 |
Correct |
9 ms |
11604 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
7 ms |
11604 KB |
Output is correct |
10 |
Correct |
7 ms |
11604 KB |
Output is correct |
11 |
Correct |
8 ms |
11648 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
7 ms |
11604 KB |
Output is correct |
14 |
Correct |
6 ms |
11604 KB |
Output is correct |
15 |
Correct |
6 ms |
11528 KB |
Output is correct |
16 |
Correct |
9 ms |
11604 KB |
Output is correct |
17 |
Correct |
7 ms |
11604 KB |
Output is correct |
18 |
Correct |
7 ms |
11604 KB |
Output is correct |
19 |
Correct |
6 ms |
11604 KB |
Output is correct |
20 |
Correct |
7 ms |
11604 KB |
Output is correct |
21 |
Correct |
8 ms |
11604 KB |
Output is correct |
22 |
Correct |
8 ms |
11632 KB |
Output is correct |
23 |
Correct |
7 ms |
11604 KB |
Output is correct |
24 |
Correct |
7 ms |
11628 KB |
Output is correct |
25 |
Correct |
8 ms |
11604 KB |
Output is correct |
26 |
Correct |
7 ms |
11604 KB |
Output is correct |
27 |
Correct |
7 ms |
11604 KB |
Output is correct |
28 |
Correct |
7 ms |
11604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11604 KB |
Output is correct |
2 |
Correct |
6 ms |
11604 KB |
Output is correct |
3 |
Correct |
7 ms |
11604 KB |
Output is correct |
4 |
Correct |
7 ms |
11604 KB |
Output is correct |
5 |
Correct |
17 ms |
11572 KB |
Output is correct |
6 |
Correct |
8 ms |
11640 KB |
Output is correct |
7 |
Correct |
9 ms |
11604 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
7 ms |
11604 KB |
Output is correct |
10 |
Correct |
7 ms |
11604 KB |
Output is correct |
11 |
Correct |
8 ms |
11648 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
7 ms |
11604 KB |
Output is correct |
14 |
Correct |
6 ms |
11604 KB |
Output is correct |
15 |
Correct |
6 ms |
11528 KB |
Output is correct |
16 |
Correct |
9 ms |
11604 KB |
Output is correct |
17 |
Correct |
7 ms |
11604 KB |
Output is correct |
18 |
Correct |
7 ms |
11604 KB |
Output is correct |
19 |
Correct |
6 ms |
11604 KB |
Output is correct |
20 |
Correct |
7 ms |
11604 KB |
Output is correct |
21 |
Correct |
8 ms |
11604 KB |
Output is correct |
22 |
Correct |
8 ms |
11632 KB |
Output is correct |
23 |
Correct |
7 ms |
11604 KB |
Output is correct |
24 |
Correct |
7 ms |
11628 KB |
Output is correct |
25 |
Correct |
8 ms |
11604 KB |
Output is correct |
26 |
Correct |
7 ms |
11604 KB |
Output is correct |
27 |
Correct |
7 ms |
11604 KB |
Output is correct |
28 |
Correct |
7 ms |
11604 KB |
Output is correct |
29 |
Correct |
150 ms |
11664 KB |
Output is correct |
30 |
Correct |
54 ms |
11604 KB |
Output is correct |
31 |
Correct |
58 ms |
11676 KB |
Output is correct |
32 |
Correct |
34 ms |
11604 KB |
Output is correct |
33 |
Correct |
14 ms |
11600 KB |
Output is correct |
34 |
Correct |
121 ms |
11728 KB |
Output is correct |
35 |
Correct |
117 ms |
11684 KB |
Output is correct |
36 |
Correct |
98 ms |
11640 KB |
Output is correct |
37 |
Correct |
71 ms |
11708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11604 KB |
Output is correct |
2 |
Correct |
6 ms |
11604 KB |
Output is correct |
3 |
Correct |
7 ms |
11604 KB |
Output is correct |
4 |
Correct |
7 ms |
11604 KB |
Output is correct |
5 |
Correct |
17 ms |
11572 KB |
Output is correct |
6 |
Correct |
8 ms |
11640 KB |
Output is correct |
7 |
Correct |
9 ms |
11604 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
7 ms |
11604 KB |
Output is correct |
10 |
Correct |
7 ms |
11604 KB |
Output is correct |
11 |
Correct |
8 ms |
11648 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
7 ms |
11604 KB |
Output is correct |
14 |
Correct |
6 ms |
11604 KB |
Output is correct |
15 |
Correct |
6 ms |
11528 KB |
Output is correct |
16 |
Correct |
9 ms |
11604 KB |
Output is correct |
17 |
Correct |
7 ms |
11604 KB |
Output is correct |
18 |
Correct |
7 ms |
11604 KB |
Output is correct |
19 |
Correct |
6 ms |
11604 KB |
Output is correct |
20 |
Correct |
7 ms |
11604 KB |
Output is correct |
21 |
Correct |
8 ms |
11604 KB |
Output is correct |
22 |
Correct |
8 ms |
11632 KB |
Output is correct |
23 |
Correct |
7 ms |
11604 KB |
Output is correct |
24 |
Correct |
7 ms |
11628 KB |
Output is correct |
25 |
Correct |
8 ms |
11604 KB |
Output is correct |
26 |
Correct |
7 ms |
11604 KB |
Output is correct |
27 |
Correct |
7 ms |
11604 KB |
Output is correct |
28 |
Correct |
7 ms |
11604 KB |
Output is correct |
29 |
Correct |
150 ms |
11664 KB |
Output is correct |
30 |
Correct |
54 ms |
11604 KB |
Output is correct |
31 |
Correct |
58 ms |
11676 KB |
Output is correct |
32 |
Correct |
34 ms |
11604 KB |
Output is correct |
33 |
Correct |
14 ms |
11600 KB |
Output is correct |
34 |
Correct |
121 ms |
11728 KB |
Output is correct |
35 |
Correct |
117 ms |
11684 KB |
Output is correct |
36 |
Correct |
98 ms |
11640 KB |
Output is correct |
37 |
Correct |
71 ms |
11708 KB |
Output is correct |
38 |
Correct |
4860 ms |
14000 KB |
Output is correct |
39 |
Correct |
306 ms |
30288 KB |
Output is correct |
40 |
Correct |
3733 ms |
13788 KB |
Output is correct |
41 |
Correct |
2881 ms |
13636 KB |
Output is correct |
42 |
Correct |
2749 ms |
14932 KB |
Output is correct |
43 |
Correct |
67 ms |
13488 KB |
Output is correct |
44 |
Correct |
2273 ms |
12084 KB |
Output is correct |
45 |
Correct |
292 ms |
25300 KB |
Output is correct |
46 |
Correct |
279 ms |
25292 KB |
Output is correct |
47 |
Correct |
454 ms |
28068 KB |
Output is correct |
48 |
Correct |
382 ms |
28076 KB |
Output is correct |
49 |
Correct |
350 ms |
25464 KB |
Output is correct |
50 |
Correct |
408 ms |
25416 KB |
Output is correct |
51 |
Correct |
99 ms |
26188 KB |
Output is correct |
52 |
Correct |
93 ms |
26096 KB |
Output is correct |
53 |
Correct |
2041 ms |
12864 KB |
Output is correct |
54 |
Correct |
228 ms |
25260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11604 KB |
Output is correct |
2 |
Correct |
8 ms |
11552 KB |
Output is correct |
3 |
Correct |
7 ms |
11624 KB |
Output is correct |
4 |
Correct |
8 ms |
11604 KB |
Output is correct |
5 |
Correct |
57 ms |
11640 KB |
Output is correct |
6 |
Correct |
6 ms |
11604 KB |
Output is correct |
7 |
Correct |
7 ms |
11604 KB |
Output is correct |
8 |
Correct |
7 ms |
11560 KB |
Output is correct |
9 |
Correct |
7 ms |
11604 KB |
Output is correct |
10 |
Correct |
7 ms |
11604 KB |
Output is correct |
11 |
Correct |
6 ms |
11604 KB |
Output is correct |
12 |
Correct |
91 ms |
11644 KB |
Output is correct |
13 |
Correct |
1027 ms |
11796 KB |
Output is correct |
14 |
Correct |
444 ms |
11652 KB |
Output is correct |
15 |
Correct |
806 ms |
11648 KB |
Output is correct |
16 |
Execution timed out |
5063 ms |
24152 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11604 KB |
Output is correct |
2 |
Correct |
6 ms |
11604 KB |
Output is correct |
3 |
Correct |
6 ms |
11604 KB |
Output is correct |
4 |
Correct |
17 ms |
11604 KB |
Output is correct |
5 |
Correct |
39 ms |
11604 KB |
Output is correct |
6 |
Correct |
6 ms |
11604 KB |
Output is correct |
7 |
Correct |
7 ms |
11604 KB |
Output is correct |
8 |
Correct |
136 ms |
11604 KB |
Output is correct |
9 |
Correct |
4797 ms |
13848 KB |
Output is correct |
10 |
Correct |
254 ms |
30184 KB |
Output is correct |
11 |
Correct |
45 ms |
11628 KB |
Output is correct |
12 |
Correct |
1577 ms |
11708 KB |
Output is correct |
13 |
Execution timed out |
5029 ms |
29344 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |