# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
551824 |
2022-04-21T16:28:52 Z |
kshitij_sodani |
Jail (JOI22_jail) |
C++14 |
|
3499 ms |
1048576 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'
const llo mod=1e9+7;
int q;
int ee;
vector<int> adj[200001];
int cc[200001];
int dd[200001];
int vis[200001];
vector<int> ss;
vector<int> tt;
vector<int> pre[501];
map<int,int> ind[501];
int ind2[200001];
int ind3[200001];
vector<int> adj2[200001];
int vis2[200001];
int vis3[200001];
void dfs(int no,int par=-1){
ss.pb(no);
if(ee==no){
tt=ss;
}
for(auto j:adj[no]){
if(j!=par){
dfs(j,no);
}
}
ss.pop_back();
}
int stt=1;
void dfs2(int no){
vis2[no]=1;
vis3[no]=1;
for(auto j:adj2[no]){
if(vis3[j]==1){
stt=0;
}
if(vis2[j]==0){
dfs2(j);
}
}
vis3[no]=0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>q;
while(q--){
int n;
cin>>n;
for(int i=0;i<n;i++){
adj[i].clear();
adj2[i].clear();
}
for(int i=0;i<n-1;i++){
int aa,bb;
cin>>aa>>bb;
aa--;
bb--;
adj[aa].pb(bb);
adj[bb].pb(aa);
}
int m;
cin>>m;
stt=1;
for(int i=0;i<n;i++){
ind2[i]=-1;
ind3[i]=-1;
}
for(int i=0;i<m;i++){
cin>>cc[i]>>dd[i];
ind[i].clear();
cc[i]--;
dd[i]--;
ind2[dd[i]]=i;
ind3[cc[i]]=i;
ee=dd[i];
dfs(cc[i]);
pre[i]=tt;
for(auto j:tt){
ind[i][j]++;
}
}
for(int i=0;i<m;i++){
for(auto j:pre[i]){
if(ind3[j]>=0 and ind3[j]!=i){
adj2[i].pb(ind3[j]);
//cout<<i<<":"<<ind3[j]<<endl;
}
if(ind2[j]>=0 and ind2[j]!=i){
adj2[ind2[j]].pb(i);
// cout<<ind2[j]<<":"<<i<<endl;
}
}
}
for(int i=0;i<m;i++){
vis2[i]=0;
}
for(int i=0;i<m;i++){
if(vis2[i]==0){
dfs2(i);
}
}
if(stt==0){
cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
}
/* string ans="No";
vector<int> ss;
for(int i=0;i<m;i++){
ss.pb(i);
}
while(true){
for(int j=0;j<n;j++){
vis[j]=0;
}
for(int j=0;j<m;j++){
vis[cc[j]]=1;
}
int ok=0;
for(auto j:ss){
vis[cc[j]]=0;
for(auto i:pre[j]){
if(vis[i]==1){
ok++;
}
}
vis[dd[j]]=1;
}
if(ok==0){
ans="Yes";
}
if(next_permutation(ss.begin(),ss.end())){
}
else{
break;
}
}
cout<<ans<<endl;*/
/*for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
int co=0;
if(i==j){
continue;
}
if(ind[j].find(cc[i])!=ind[j].end()){
if(ind[j].find(dd[i])!=ind[j].end()){
ans="No";
}
}
for(auto jj:pre[j]){
if(ind[i].find(dd[j]))
}
if(ind[j].find(dd[i])!=ind[j].end()){
if(ind[i].find(pre[j].back())!=ind[i].end()){
ans="No";
break;
}
}
}
}*/
// cout<<ans<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9720 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
18 ms |
9812 KB |
Output is correct |
5 |
Correct |
32 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9780 KB |
Output is correct |
8 |
Correct |
19 ms |
10660 KB |
Output is correct |
9 |
Correct |
1866 ms |
153520 KB |
Output is correct |
10 |
Runtime error |
3499 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9780 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9812 KB |
Output is correct |
4 |
Correct |
7 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9784 KB |
Output is correct |
6 |
Correct |
7 ms |
9784 KB |
Output is correct |
7 |
Correct |
9 ms |
9816 KB |
Output is correct |
8 |
Correct |
8 ms |
9804 KB |
Output is correct |
9 |
Correct |
7 ms |
9800 KB |
Output is correct |
10 |
Correct |
6 ms |
9812 KB |
Output is correct |
11 |
Correct |
6 ms |
9832 KB |
Output is correct |
12 |
Correct |
6 ms |
9812 KB |
Output is correct |
13 |
Correct |
5 ms |
9788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9780 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9812 KB |
Output is correct |
4 |
Correct |
7 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9784 KB |
Output is correct |
6 |
Correct |
7 ms |
9784 KB |
Output is correct |
7 |
Correct |
9 ms |
9816 KB |
Output is correct |
8 |
Correct |
8 ms |
9804 KB |
Output is correct |
9 |
Correct |
7 ms |
9800 KB |
Output is correct |
10 |
Correct |
6 ms |
9812 KB |
Output is correct |
11 |
Correct |
6 ms |
9832 KB |
Output is correct |
12 |
Correct |
6 ms |
9812 KB |
Output is correct |
13 |
Correct |
5 ms |
9788 KB |
Output is correct |
14 |
Correct |
5 ms |
9772 KB |
Output is correct |
15 |
Correct |
5 ms |
9768 KB |
Output is correct |
16 |
Correct |
7 ms |
9904 KB |
Output is correct |
17 |
Correct |
7 ms |
9812 KB |
Output is correct |
18 |
Correct |
7 ms |
9812 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
9 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9812 KB |
Output is correct |
22 |
Correct |
7 ms |
9812 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9772 KB |
Output is correct |
25 |
Correct |
7 ms |
9812 KB |
Output is correct |
26 |
Correct |
6 ms |
9800 KB |
Output is correct |
27 |
Correct |
7 ms |
9812 KB |
Output is correct |
28 |
Correct |
5 ms |
9708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9780 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9812 KB |
Output is correct |
4 |
Correct |
7 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9784 KB |
Output is correct |
6 |
Correct |
7 ms |
9784 KB |
Output is correct |
7 |
Correct |
9 ms |
9816 KB |
Output is correct |
8 |
Correct |
8 ms |
9804 KB |
Output is correct |
9 |
Correct |
7 ms |
9800 KB |
Output is correct |
10 |
Correct |
6 ms |
9812 KB |
Output is correct |
11 |
Correct |
6 ms |
9832 KB |
Output is correct |
12 |
Correct |
6 ms |
9812 KB |
Output is correct |
13 |
Correct |
5 ms |
9788 KB |
Output is correct |
14 |
Correct |
5 ms |
9772 KB |
Output is correct |
15 |
Correct |
5 ms |
9768 KB |
Output is correct |
16 |
Correct |
7 ms |
9904 KB |
Output is correct |
17 |
Correct |
7 ms |
9812 KB |
Output is correct |
18 |
Correct |
7 ms |
9812 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
9 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9812 KB |
Output is correct |
22 |
Correct |
7 ms |
9812 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9772 KB |
Output is correct |
25 |
Correct |
7 ms |
9812 KB |
Output is correct |
26 |
Correct |
6 ms |
9800 KB |
Output is correct |
27 |
Correct |
7 ms |
9812 KB |
Output is correct |
28 |
Correct |
5 ms |
9708 KB |
Output is correct |
29 |
Correct |
20 ms |
10708 KB |
Output is correct |
30 |
Correct |
10 ms |
9812 KB |
Output is correct |
31 |
Correct |
14 ms |
10068 KB |
Output is correct |
32 |
Correct |
11 ms |
9912 KB |
Output is correct |
33 |
Correct |
8 ms |
9784 KB |
Output is correct |
34 |
Correct |
10 ms |
9912 KB |
Output is correct |
35 |
Correct |
17 ms |
10272 KB |
Output is correct |
36 |
Correct |
10 ms |
9812 KB |
Output is correct |
37 |
Correct |
9 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9780 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9812 KB |
Output is correct |
4 |
Correct |
7 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9784 KB |
Output is correct |
6 |
Correct |
7 ms |
9784 KB |
Output is correct |
7 |
Correct |
9 ms |
9816 KB |
Output is correct |
8 |
Correct |
8 ms |
9804 KB |
Output is correct |
9 |
Correct |
7 ms |
9800 KB |
Output is correct |
10 |
Correct |
6 ms |
9812 KB |
Output is correct |
11 |
Correct |
6 ms |
9832 KB |
Output is correct |
12 |
Correct |
6 ms |
9812 KB |
Output is correct |
13 |
Correct |
5 ms |
9788 KB |
Output is correct |
14 |
Correct |
5 ms |
9772 KB |
Output is correct |
15 |
Correct |
5 ms |
9768 KB |
Output is correct |
16 |
Correct |
7 ms |
9904 KB |
Output is correct |
17 |
Correct |
7 ms |
9812 KB |
Output is correct |
18 |
Correct |
7 ms |
9812 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
9 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9812 KB |
Output is correct |
22 |
Correct |
7 ms |
9812 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9772 KB |
Output is correct |
25 |
Correct |
7 ms |
9812 KB |
Output is correct |
26 |
Correct |
6 ms |
9800 KB |
Output is correct |
27 |
Correct |
7 ms |
9812 KB |
Output is correct |
28 |
Correct |
5 ms |
9708 KB |
Output is correct |
29 |
Correct |
20 ms |
10708 KB |
Output is correct |
30 |
Correct |
10 ms |
9812 KB |
Output is correct |
31 |
Correct |
14 ms |
10068 KB |
Output is correct |
32 |
Correct |
11 ms |
9912 KB |
Output is correct |
33 |
Correct |
8 ms |
9784 KB |
Output is correct |
34 |
Correct |
10 ms |
9912 KB |
Output is correct |
35 |
Correct |
17 ms |
10272 KB |
Output is correct |
36 |
Correct |
10 ms |
9812 KB |
Output is correct |
37 |
Correct |
9 ms |
9812 KB |
Output is correct |
38 |
Correct |
1944 ms |
153004 KB |
Output is correct |
39 |
Runtime error |
3458 ms |
1048576 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
14 ms |
9944 KB |
Output is correct |
6 |
Correct |
6 ms |
9768 KB |
Output is correct |
7 |
Correct |
6 ms |
9684 KB |
Output is correct |
8 |
Correct |
6 ms |
9772 KB |
Output is correct |
9 |
Correct |
6 ms |
9684 KB |
Output is correct |
10 |
Correct |
5 ms |
9684 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
9 ms |
9868 KB |
Output is correct |
13 |
Correct |
58 ms |
10236 KB |
Output is correct |
14 |
Correct |
79 ms |
10556 KB |
Output is correct |
15 |
Correct |
72 ms |
10344 KB |
Output is correct |
16 |
Runtime error |
1990 ms |
31528 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9720 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
18 ms |
9812 KB |
Output is correct |
5 |
Correct |
32 ms |
9812 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9780 KB |
Output is correct |
8 |
Correct |
19 ms |
10660 KB |
Output is correct |
9 |
Correct |
1866 ms |
153520 KB |
Output is correct |
10 |
Runtime error |
3499 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |