# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994189 |
2024-06-07T08:32:05 Z |
vjudge1 |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
258568 KB |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
void solve();
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
cin>>t;
while (t--) solve();
return 0;
}
const int maxn = 120'000;
vector<vector<int>> g(maxn);
vector<int> num(maxn);
int n,m;
vector<int> s(maxn),t(maxn);
vector<vector<int>> path(maxn);
vector<bool> has(maxn,false);
bool dfs (int v, int start, int par=-1){
bool ret=false;
if (v==t[start]) return true;
for (int to : g[v]){
if (to==par) continue;
ret = ret || dfs(to, start, v);
if (ret){
num[to]++;
path[start].push_back(to);
break;
}
}
return ret;
}
void solve(){
cin>>n;
path.assign(maxn, {});
num.assign(maxn,0);
has.assign(maxn,false);
g.assign(maxn,{});
queue<int> q;
for (int i = 1; i < n; i++)
{
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
cin>>m;
for (int i = 1; i <= m; i++)
{
cin>>s[i]>>t[i];
dfs(s[i], i);
num[s[i]]++;
q.push(i);
has[s[i]]=true;
}
bool change=true;
while (change){
change=false;
int sz=q.size();
for (int i=0;i<sz;i++){
int cur=q.front();
q.pop();
bool rem=num[t[cur]]-1;
for (int j : path[cur]){
if (has[j]) rem=true;
}
if (rem) {
q.push(cur);
continue;
}
change=true;
has[s[cur]]=false;
num[s[cur]]--;
for (int j : path[cur]){
num[j]--;
}
}
}
if (q.empty()){
cout<<"Yes\n";
}
else {
cout<<"No\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7512 KB |
Output is correct |
2 |
Correct |
5 ms |
7364 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
356 ms |
7820 KB |
Output is correct |
5 |
Correct |
748 ms |
8272 KB |
Output is correct |
6 |
Correct |
20 ms |
7512 KB |
Output is correct |
7 |
Correct |
18 ms |
7516 KB |
Output is correct |
8 |
Correct |
21 ms |
7632 KB |
Output is correct |
9 |
Correct |
763 ms |
24404 KB |
Output is correct |
10 |
Incorrect |
1430 ms |
258568 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
18 ms |
7572 KB |
Output is correct |
4 |
Correct |
17 ms |
7512 KB |
Output is correct |
5 |
Correct |
17 ms |
7592 KB |
Output is correct |
6 |
Correct |
19 ms |
7560 KB |
Output is correct |
7 |
Correct |
18 ms |
7516 KB |
Output is correct |
8 |
Correct |
18 ms |
7516 KB |
Output is correct |
9 |
Correct |
19 ms |
7516 KB |
Output is correct |
10 |
Correct |
18 ms |
7592 KB |
Output is correct |
11 |
Correct |
18 ms |
7516 KB |
Output is correct |
12 |
Correct |
19 ms |
7516 KB |
Output is correct |
13 |
Correct |
18 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
18 ms |
7572 KB |
Output is correct |
4 |
Correct |
17 ms |
7512 KB |
Output is correct |
5 |
Correct |
17 ms |
7592 KB |
Output is correct |
6 |
Correct |
19 ms |
7560 KB |
Output is correct |
7 |
Correct |
18 ms |
7516 KB |
Output is correct |
8 |
Correct |
18 ms |
7516 KB |
Output is correct |
9 |
Correct |
19 ms |
7516 KB |
Output is correct |
10 |
Correct |
18 ms |
7592 KB |
Output is correct |
11 |
Correct |
18 ms |
7516 KB |
Output is correct |
12 |
Correct |
19 ms |
7516 KB |
Output is correct |
13 |
Correct |
18 ms |
7512 KB |
Output is correct |
14 |
Correct |
4 ms |
7516 KB |
Output is correct |
15 |
Correct |
4 ms |
7544 KB |
Output is correct |
16 |
Correct |
19 ms |
7608 KB |
Output is correct |
17 |
Correct |
18 ms |
7512 KB |
Output is correct |
18 |
Correct |
19 ms |
7596 KB |
Output is correct |
19 |
Correct |
18 ms |
7552 KB |
Output is correct |
20 |
Correct |
18 ms |
7568 KB |
Output is correct |
21 |
Correct |
17 ms |
7516 KB |
Output is correct |
22 |
Correct |
19 ms |
7512 KB |
Output is correct |
23 |
Correct |
18 ms |
7516 KB |
Output is correct |
24 |
Correct |
18 ms |
7512 KB |
Output is correct |
25 |
Correct |
27 ms |
7516 KB |
Output is correct |
26 |
Correct |
18 ms |
7516 KB |
Output is correct |
27 |
Correct |
18 ms |
7516 KB |
Output is correct |
28 |
Correct |
17 ms |
7552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
18 ms |
7572 KB |
Output is correct |
4 |
Correct |
17 ms |
7512 KB |
Output is correct |
5 |
Correct |
17 ms |
7592 KB |
Output is correct |
6 |
Correct |
19 ms |
7560 KB |
Output is correct |
7 |
Correct |
18 ms |
7516 KB |
Output is correct |
8 |
Correct |
18 ms |
7516 KB |
Output is correct |
9 |
Correct |
19 ms |
7516 KB |
Output is correct |
10 |
Correct |
18 ms |
7592 KB |
Output is correct |
11 |
Correct |
18 ms |
7516 KB |
Output is correct |
12 |
Correct |
19 ms |
7516 KB |
Output is correct |
13 |
Correct |
18 ms |
7512 KB |
Output is correct |
14 |
Correct |
4 ms |
7516 KB |
Output is correct |
15 |
Correct |
4 ms |
7544 KB |
Output is correct |
16 |
Correct |
19 ms |
7608 KB |
Output is correct |
17 |
Correct |
18 ms |
7512 KB |
Output is correct |
18 |
Correct |
19 ms |
7596 KB |
Output is correct |
19 |
Correct |
18 ms |
7552 KB |
Output is correct |
20 |
Correct |
18 ms |
7568 KB |
Output is correct |
21 |
Correct |
17 ms |
7516 KB |
Output is correct |
22 |
Correct |
19 ms |
7512 KB |
Output is correct |
23 |
Correct |
18 ms |
7516 KB |
Output is correct |
24 |
Correct |
18 ms |
7512 KB |
Output is correct |
25 |
Correct |
27 ms |
7516 KB |
Output is correct |
26 |
Correct |
18 ms |
7516 KB |
Output is correct |
27 |
Correct |
18 ms |
7516 KB |
Output is correct |
28 |
Correct |
17 ms |
7552 KB |
Output is correct |
29 |
Correct |
21 ms |
7516 KB |
Output is correct |
30 |
Correct |
20 ms |
7516 KB |
Output is correct |
31 |
Correct |
21 ms |
7612 KB |
Output is correct |
32 |
Correct |
19 ms |
7516 KB |
Output is correct |
33 |
Correct |
19 ms |
7512 KB |
Output is correct |
34 |
Correct |
20 ms |
7512 KB |
Output is correct |
35 |
Correct |
19 ms |
7516 KB |
Output is correct |
36 |
Correct |
19 ms |
7600 KB |
Output is correct |
37 |
Correct |
19 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
18 ms |
7572 KB |
Output is correct |
4 |
Correct |
17 ms |
7512 KB |
Output is correct |
5 |
Correct |
17 ms |
7592 KB |
Output is correct |
6 |
Correct |
19 ms |
7560 KB |
Output is correct |
7 |
Correct |
18 ms |
7516 KB |
Output is correct |
8 |
Correct |
18 ms |
7516 KB |
Output is correct |
9 |
Correct |
19 ms |
7516 KB |
Output is correct |
10 |
Correct |
18 ms |
7592 KB |
Output is correct |
11 |
Correct |
18 ms |
7516 KB |
Output is correct |
12 |
Correct |
19 ms |
7516 KB |
Output is correct |
13 |
Correct |
18 ms |
7512 KB |
Output is correct |
14 |
Correct |
4 ms |
7516 KB |
Output is correct |
15 |
Correct |
4 ms |
7544 KB |
Output is correct |
16 |
Correct |
19 ms |
7608 KB |
Output is correct |
17 |
Correct |
18 ms |
7512 KB |
Output is correct |
18 |
Correct |
19 ms |
7596 KB |
Output is correct |
19 |
Correct |
18 ms |
7552 KB |
Output is correct |
20 |
Correct |
18 ms |
7568 KB |
Output is correct |
21 |
Correct |
17 ms |
7516 KB |
Output is correct |
22 |
Correct |
19 ms |
7512 KB |
Output is correct |
23 |
Correct |
18 ms |
7516 KB |
Output is correct |
24 |
Correct |
18 ms |
7512 KB |
Output is correct |
25 |
Correct |
27 ms |
7516 KB |
Output is correct |
26 |
Correct |
18 ms |
7516 KB |
Output is correct |
27 |
Correct |
18 ms |
7516 KB |
Output is correct |
28 |
Correct |
17 ms |
7552 KB |
Output is correct |
29 |
Correct |
21 ms |
7516 KB |
Output is correct |
30 |
Correct |
20 ms |
7516 KB |
Output is correct |
31 |
Correct |
21 ms |
7612 KB |
Output is correct |
32 |
Correct |
19 ms |
7516 KB |
Output is correct |
33 |
Correct |
19 ms |
7512 KB |
Output is correct |
34 |
Correct |
20 ms |
7512 KB |
Output is correct |
35 |
Correct |
19 ms |
7516 KB |
Output is correct |
36 |
Correct |
19 ms |
7600 KB |
Output is correct |
37 |
Correct |
19 ms |
7512 KB |
Output is correct |
38 |
Correct |
748 ms |
24392 KB |
Output is correct |
39 |
Incorrect |
1408 ms |
258540 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
5 ms |
7512 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
731 ms |
7524 KB |
Output is correct |
6 |
Correct |
20 ms |
7512 KB |
Output is correct |
7 |
Correct |
20 ms |
7516 KB |
Output is correct |
8 |
Correct |
19 ms |
7544 KB |
Output is correct |
9 |
Correct |
19 ms |
7512 KB |
Output is correct |
10 |
Correct |
17 ms |
7516 KB |
Output is correct |
11 |
Correct |
19 ms |
7516 KB |
Output is correct |
12 |
Correct |
19 ms |
7516 KB |
Output is correct |
13 |
Correct |
753 ms |
8064 KB |
Output is correct |
14 |
Correct |
753 ms |
8276 KB |
Output is correct |
15 |
Correct |
802 ms |
8020 KB |
Output is correct |
16 |
Execution timed out |
5059 ms |
13376 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7512 KB |
Output is correct |
2 |
Correct |
5 ms |
7364 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
356 ms |
7820 KB |
Output is correct |
5 |
Correct |
748 ms |
8272 KB |
Output is correct |
6 |
Correct |
20 ms |
7512 KB |
Output is correct |
7 |
Correct |
18 ms |
7516 KB |
Output is correct |
8 |
Correct |
21 ms |
7632 KB |
Output is correct |
9 |
Correct |
763 ms |
24404 KB |
Output is correct |
10 |
Incorrect |
1430 ms |
258568 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |