# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
876917 |
2023-11-22T13:38:17 Z |
Ivkosqn |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
11604 KB |
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 120010;
int n, m, s[maxn], f[maxn], used[maxn], bef[maxn];
vector<int> v[maxn], g[maxn], paths[510];
int usedp[maxn];
void find_path(int ver){
used[ver] = 1;
for(int nb : v[ver]){
if(used[nb])
continue;
bef[nb] = ver;
find_path(nb);
}
}
void read(){
cin >> n;
for(int i = 1;i <= n;i++){
v[i].clear();
g[i].clear();
}
for(int i = 1;i <= m;i++)
paths[i].clear();
for(int i = 1;i <= n - 1;i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
cin >> m;
for(int i = 1;i <= m;i++){
cin >> s[i] >> f[i];
for(int k = 1;k <= n;k++)
used[k] = 0;
find_path(s[i]);
paths[i].push_back(f[i]);
int x = f[i];
while(x != s[i]){
x = bef[x];
paths[i].push_back(x);
}
sort(paths[i].begin(), paths[i].end());
}
}
bool cycle = 0;
void DFS(int ver){
used[ver] = 1;
for(int nb : g[ver]){
if(!used[nb])
DFS(nb);
else if(used[nb] == 1)
cycle = 1;
}
used[ver] = 2;
}
void dfs(int ver){
used[ver] = 1;
for(int nb : v[ver]){
if(used[nb])
continue;
dfs(nb);
}
}
void solve(){
read();
for(int i = 1;i <= m;i++){
for(int nb : paths[i])
usedp[nb] = 1;
for(int j = 1;j <= m;j++){
if(i == j)
continue;
for(int k = 1;k <= n;k++)
used[k] = 0;
used[s[j]] = 1;
dfs(s[i]);
if(!used[f[i]]){
g[j].push_back(i);
continue;
}
if(usedp[s[j]]){
g[j].push_back(i);
continue;
}
int ans = -1, l = 0, r = paths[j].size() - 1;
while(l <= r){
int mid = (l + r) / 2;
if(paths[j][mid] <= f[i])
l = mid + 1, ans = mid;
else
r = mid - 1;
}
if(ans != -1 && paths[j][ans] == f[i]){
g[j].push_back(i);
}
}
for(int nb : paths[i])
usedp[nb] = 0;
}
cycle = 0;
memset(used, 0, sizeof(used));
for(int i = 1;i <= n;i++){
if(!used[i]){
DFS(i);
}
}
if(cycle)
cout << "No\n";
else
cout << "Yes\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7004 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
7004 KB |
Output is correct |
4 |
Correct |
13 ms |
7108 KB |
Output is correct |
5 |
Correct |
38 ms |
7004 KB |
Output is correct |
6 |
Correct |
3 ms |
7004 KB |
Output is correct |
7 |
Correct |
3 ms |
7100 KB |
Output is correct |
8 |
Correct |
198 ms |
7248 KB |
Output is correct |
9 |
Execution timed out |
5049 ms |
7296 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7004 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
7004 KB |
Output is correct |
4 |
Correct |
2 ms |
7004 KB |
Output is correct |
5 |
Correct |
3 ms |
7004 KB |
Output is correct |
6 |
Correct |
3 ms |
7000 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
7004 KB |
Output is correct |
10 |
Correct |
3 ms |
7004 KB |
Output is correct |
11 |
Correct |
3 ms |
7004 KB |
Output is correct |
12 |
Correct |
2 ms |
7004 KB |
Output is correct |
13 |
Correct |
3 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7004 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
7004 KB |
Output is correct |
4 |
Correct |
2 ms |
7004 KB |
Output is correct |
5 |
Correct |
3 ms |
7004 KB |
Output is correct |
6 |
Correct |
3 ms |
7000 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
7004 KB |
Output is correct |
10 |
Correct |
3 ms |
7004 KB |
Output is correct |
11 |
Correct |
3 ms |
7004 KB |
Output is correct |
12 |
Correct |
2 ms |
7004 KB |
Output is correct |
13 |
Correct |
3 ms |
7004 KB |
Output is correct |
14 |
Correct |
2 ms |
7004 KB |
Output is correct |
15 |
Correct |
2 ms |
7096 KB |
Output is correct |
16 |
Correct |
3 ms |
7004 KB |
Output is correct |
17 |
Correct |
3 ms |
7004 KB |
Output is correct |
18 |
Correct |
3 ms |
7004 KB |
Output is correct |
19 |
Correct |
2 ms |
7004 KB |
Output is correct |
20 |
Correct |
3 ms |
7004 KB |
Output is correct |
21 |
Correct |
3 ms |
7004 KB |
Output is correct |
22 |
Correct |
3 ms |
7004 KB |
Output is correct |
23 |
Correct |
2 ms |
7004 KB |
Output is correct |
24 |
Correct |
2 ms |
7004 KB |
Output is correct |
25 |
Correct |
4 ms |
7004 KB |
Output is correct |
26 |
Correct |
2 ms |
7004 KB |
Output is correct |
27 |
Correct |
3 ms |
7004 KB |
Output is correct |
28 |
Correct |
3 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7004 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
7004 KB |
Output is correct |
4 |
Correct |
2 ms |
7004 KB |
Output is correct |
5 |
Correct |
3 ms |
7004 KB |
Output is correct |
6 |
Correct |
3 ms |
7000 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
7004 KB |
Output is correct |
10 |
Correct |
3 ms |
7004 KB |
Output is correct |
11 |
Correct |
3 ms |
7004 KB |
Output is correct |
12 |
Correct |
2 ms |
7004 KB |
Output is correct |
13 |
Correct |
3 ms |
7004 KB |
Output is correct |
14 |
Correct |
2 ms |
7004 KB |
Output is correct |
15 |
Correct |
2 ms |
7096 KB |
Output is correct |
16 |
Correct |
3 ms |
7004 KB |
Output is correct |
17 |
Correct |
3 ms |
7004 KB |
Output is correct |
18 |
Correct |
3 ms |
7004 KB |
Output is correct |
19 |
Correct |
2 ms |
7004 KB |
Output is correct |
20 |
Correct |
3 ms |
7004 KB |
Output is correct |
21 |
Correct |
3 ms |
7004 KB |
Output is correct |
22 |
Correct |
3 ms |
7004 KB |
Output is correct |
23 |
Correct |
2 ms |
7004 KB |
Output is correct |
24 |
Correct |
2 ms |
7004 KB |
Output is correct |
25 |
Correct |
4 ms |
7004 KB |
Output is correct |
26 |
Correct |
2 ms |
7004 KB |
Output is correct |
27 |
Correct |
3 ms |
7004 KB |
Output is correct |
28 |
Correct |
3 ms |
7004 KB |
Output is correct |
29 |
Correct |
197 ms |
7240 KB |
Output is correct |
30 |
Correct |
92 ms |
7004 KB |
Output is correct |
31 |
Correct |
86 ms |
7152 KB |
Output is correct |
32 |
Correct |
55 ms |
7120 KB |
Output is correct |
33 |
Correct |
13 ms |
7256 KB |
Output is correct |
34 |
Correct |
155 ms |
7112 KB |
Output is correct |
35 |
Correct |
157 ms |
7180 KB |
Output is correct |
36 |
Correct |
124 ms |
7092 KB |
Output is correct |
37 |
Correct |
95 ms |
7612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7004 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
7004 KB |
Output is correct |
4 |
Correct |
2 ms |
7004 KB |
Output is correct |
5 |
Correct |
3 ms |
7004 KB |
Output is correct |
6 |
Correct |
3 ms |
7000 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
3 ms |
7004 KB |
Output is correct |
10 |
Correct |
3 ms |
7004 KB |
Output is correct |
11 |
Correct |
3 ms |
7004 KB |
Output is correct |
12 |
Correct |
2 ms |
7004 KB |
Output is correct |
13 |
Correct |
3 ms |
7004 KB |
Output is correct |
14 |
Correct |
2 ms |
7004 KB |
Output is correct |
15 |
Correct |
2 ms |
7096 KB |
Output is correct |
16 |
Correct |
3 ms |
7004 KB |
Output is correct |
17 |
Correct |
3 ms |
7004 KB |
Output is correct |
18 |
Correct |
3 ms |
7004 KB |
Output is correct |
19 |
Correct |
2 ms |
7004 KB |
Output is correct |
20 |
Correct |
3 ms |
7004 KB |
Output is correct |
21 |
Correct |
3 ms |
7004 KB |
Output is correct |
22 |
Correct |
3 ms |
7004 KB |
Output is correct |
23 |
Correct |
2 ms |
7004 KB |
Output is correct |
24 |
Correct |
2 ms |
7004 KB |
Output is correct |
25 |
Correct |
4 ms |
7004 KB |
Output is correct |
26 |
Correct |
2 ms |
7004 KB |
Output is correct |
27 |
Correct |
3 ms |
7004 KB |
Output is correct |
28 |
Correct |
3 ms |
7004 KB |
Output is correct |
29 |
Correct |
197 ms |
7240 KB |
Output is correct |
30 |
Correct |
92 ms |
7004 KB |
Output is correct |
31 |
Correct |
86 ms |
7152 KB |
Output is correct |
32 |
Correct |
55 ms |
7120 KB |
Output is correct |
33 |
Correct |
13 ms |
7256 KB |
Output is correct |
34 |
Correct |
155 ms |
7112 KB |
Output is correct |
35 |
Correct |
157 ms |
7180 KB |
Output is correct |
36 |
Correct |
124 ms |
7092 KB |
Output is correct |
37 |
Correct |
95 ms |
7612 KB |
Output is correct |
38 |
Execution timed out |
5009 ms |
7532 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7004 KB |
Output is correct |
2 |
Correct |
1 ms |
7004 KB |
Output is correct |
3 |
Correct |
1 ms |
7004 KB |
Output is correct |
4 |
Correct |
1 ms |
7004 KB |
Output is correct |
5 |
Correct |
21 ms |
7104 KB |
Output is correct |
6 |
Correct |
2 ms |
7004 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
2 ms |
7004 KB |
Output is correct |
10 |
Correct |
3 ms |
7004 KB |
Output is correct |
11 |
Correct |
2 ms |
7004 KB |
Output is correct |
12 |
Correct |
125 ms |
7092 KB |
Output is correct |
13 |
Correct |
1012 ms |
7172 KB |
Output is correct |
14 |
Correct |
495 ms |
7096 KB |
Output is correct |
15 |
Correct |
811 ms |
7104 KB |
Output is correct |
16 |
Execution timed out |
5022 ms |
11604 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7004 KB |
Output is correct |
2 |
Correct |
2 ms |
7004 KB |
Output is correct |
3 |
Correct |
2 ms |
7004 KB |
Output is correct |
4 |
Correct |
13 ms |
7108 KB |
Output is correct |
5 |
Correct |
38 ms |
7004 KB |
Output is correct |
6 |
Correct |
3 ms |
7004 KB |
Output is correct |
7 |
Correct |
3 ms |
7100 KB |
Output is correct |
8 |
Correct |
198 ms |
7248 KB |
Output is correct |
9 |
Execution timed out |
5049 ms |
7296 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |