# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
875638 |
2023-11-20T09:17:57 Z |
dimashhh |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
36432 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10, MOD = 998244353;
vector<int> g[N];
int timer = 0,tin[N],tout[N],n,m,s[N],t[N],blocked[N],c[N],pp[N];
void dfs(int v,int pr = 0){
tin[v] = ++timer;
pp[v] = pr;
for(int to:g[v]){
if(to == pr) continue;
dfs(to,v);
}
tout[v] = ++timer;
}
bool is(int v,int u){
return (tin[v] <= tin[u] && tout[v] >= tout[u]);
}
bool can(int i){
int v =s[i],u = t[i];
while(!is(v,u)){
if(c[v] && c[v] != i) return false;
v = pp[v];
}
while(!is(u,v)){
if(c[u] && c[u] != i) return false;
u = pp[u];
}
// assert(v == u);
if((c[v] && c[v] != i) || (c[u] && c[u] != i)) return false;
return 1;
}
void test(){
timer =0 ;
cin >> n;
for(int i = 1;i <= n;i++)
g[i].clear();
for(int i = 1;i <= n - 1;i++){
int x,y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
c[x] = c[y] = 0;
}
dfs(1);
cin >> m;
for(int i = 1;i <= m;i++){
blocked[i] = 0;
}
for(int i = 1;i <= m;++i){
cin >> s[i] >> t[i];
c[s[i]] = i;
}
// cout << can(2);
for(int i = 1;i <= m;i++){
bool ok = false;
for(int j = 1;j <= m;j++){
// cout << .
// cout << j << ' ' << can(j) << '\n';
if(blocked[j] || !can(j)) continue;
blocked[j] = 1;
c[s[j]] = 0;
c[t[j]] =j;
ok = 1;
break;
}
// cout << can(1) << '\n';
if(!ok){
cout << "No\n";
return;
}
}
cout << "Yes\n";
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++)
{
test();
}
}
Compilation message
jail.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
76 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25692 KB |
Output is correct |
2 |
Correct |
4 ms |
25704 KB |
Output is correct |
3 |
Correct |
4 ms |
25688 KB |
Output is correct |
4 |
Correct |
10 ms |
25728 KB |
Output is correct |
5 |
Correct |
17 ms |
25736 KB |
Output is correct |
6 |
Correct |
5 ms |
25692 KB |
Output is correct |
7 |
Correct |
5 ms |
25716 KB |
Output is correct |
8 |
Correct |
7 ms |
25692 KB |
Output is correct |
9 |
Correct |
1485 ms |
26204 KB |
Output is correct |
10 |
Execution timed out |
5022 ms |
36432 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
25692 KB |
Output is correct |
2 |
Correct |
4 ms |
25692 KB |
Output is correct |
3 |
Correct |
5 ms |
25692 KB |
Output is correct |
4 |
Correct |
5 ms |
25532 KB |
Output is correct |
5 |
Correct |
5 ms |
25944 KB |
Output is correct |
6 |
Correct |
5 ms |
25692 KB |
Output is correct |
7 |
Correct |
5 ms |
25736 KB |
Output is correct |
8 |
Incorrect |
5 ms |
25688 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
25692 KB |
Output is correct |
2 |
Correct |
4 ms |
25692 KB |
Output is correct |
3 |
Correct |
5 ms |
25692 KB |
Output is correct |
4 |
Correct |
5 ms |
25532 KB |
Output is correct |
5 |
Correct |
5 ms |
25944 KB |
Output is correct |
6 |
Correct |
5 ms |
25692 KB |
Output is correct |
7 |
Correct |
5 ms |
25736 KB |
Output is correct |
8 |
Incorrect |
5 ms |
25688 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
25692 KB |
Output is correct |
2 |
Correct |
4 ms |
25692 KB |
Output is correct |
3 |
Correct |
5 ms |
25692 KB |
Output is correct |
4 |
Correct |
5 ms |
25532 KB |
Output is correct |
5 |
Correct |
5 ms |
25944 KB |
Output is correct |
6 |
Correct |
5 ms |
25692 KB |
Output is correct |
7 |
Correct |
5 ms |
25736 KB |
Output is correct |
8 |
Incorrect |
5 ms |
25688 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
25692 KB |
Output is correct |
2 |
Correct |
4 ms |
25692 KB |
Output is correct |
3 |
Correct |
5 ms |
25692 KB |
Output is correct |
4 |
Correct |
5 ms |
25532 KB |
Output is correct |
5 |
Correct |
5 ms |
25944 KB |
Output is correct |
6 |
Correct |
5 ms |
25692 KB |
Output is correct |
7 |
Correct |
5 ms |
25736 KB |
Output is correct |
8 |
Incorrect |
5 ms |
25688 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25692 KB |
Output is correct |
2 |
Correct |
5 ms |
25692 KB |
Output is correct |
3 |
Correct |
4 ms |
25544 KB |
Output is correct |
4 |
Correct |
5 ms |
25704 KB |
Output is correct |
5 |
Correct |
7 ms |
25692 KB |
Output is correct |
6 |
Incorrect |
4 ms |
25692 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25692 KB |
Output is correct |
2 |
Correct |
4 ms |
25704 KB |
Output is correct |
3 |
Correct |
4 ms |
25688 KB |
Output is correct |
4 |
Correct |
10 ms |
25728 KB |
Output is correct |
5 |
Correct |
17 ms |
25736 KB |
Output is correct |
6 |
Correct |
5 ms |
25692 KB |
Output is correct |
7 |
Correct |
5 ms |
25716 KB |
Output is correct |
8 |
Correct |
7 ms |
25692 KB |
Output is correct |
9 |
Correct |
1485 ms |
26204 KB |
Output is correct |
10 |
Execution timed out |
5022 ms |
36432 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |