Submission #555842

# Submission time Handle Problem Language Result Execution time Memory
555842 2022-05-01T16:32:33 Z Koosha_mv Jail (JOI22_jail) C++14
72 / 100
5000 ms 526092 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=2e5+99;

int n,m,ans,a[N],b[N],h[N],vis[N],par[N];
vector<int> g[N];
vector<pair<int,int>> vec[N];

void dfs1(int u,int p){
	for(auto v : g[u]){
		if(v==p) continue ;
		par[v]=u;
		h[v]=h[u]+1;
		dfs1(v,u);
	}
}
void dfs2(int u){
	vis[u]=1;
	for(auto v : g[u]){
		if(vis[v]==1) ans=0;
		if(vis[v]) continue ;
		dfs2(v);
	}
	vis[u]=2;
}
void Main(){
	cin>>n;
	f(i,1,n){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}	
	cin>>m;
	f(i,1,m+1){
		cin>>a[i]>>b[i];
		vec[a[i]].pb({i,0});
		vec[b[i]].pb({i,1});
	}
	dfs1(1,1);
	f(i,1,n+1) g[i].clear();
	f(i,1,m+1){
		//eror(i);
		int u=a[i],v=b[i];
		while(u!=v){
			//cout<<u<<" "<<v<<endl;
			if(h[u]<h[v]) swap(u,v);
			//cout<<u<<" -> "<<par[u]<<endl;
			for(auto p : vec[u]){
				if(p.F==i) continue ;
				if(p.S==1){
					//cout<<i<<" -> "<<p.F<<endl;;
					g[i].pb(p.F);
				}
				else{
					//cout<<p.F<<" --> "<<i<<endl;
					g[p.F].pb(i);
				}
			}
			u=par[u];
		}
		for(auto p : vec[u]){
			if(p.F==i) continue ;
			if(p.S==1){
				//cout<<i<<" -> "<<p.F<<endl;;
				g[i].pb(p.F);
			}
			else{
				//cout<<p.F<<" --> "<<i<<endl;
				g[p.F].pb(i);
			}
		}
	}
	ans=1;
	f(i,1,m+1){
		if(vis[i]) continue;
		dfs2(i);
	}
	if(ans) cout<<"Yes"<<'\n';
	else cout<<"No"<<'\n';
}

int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--){
		Main();
		f(i,1,max(n,m)+1) g[i].clear(),vec[i].clear(),vis[i]=0;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9744 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 12 ms 9760 KB Output is correct
5 Correct 24 ms 9776 KB Output is correct
6 Correct 6 ms 9804 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 90 ms 13564 KB Output is correct
10 Correct 203 ms 24488 KB Output is correct
11 Correct 10 ms 9812 KB Output is correct
12 Correct 43 ms 10760 KB Output is correct
13 Correct 141 ms 55520 KB Output is correct
14 Correct 172 ms 69676 KB Output is correct
15 Execution timed out 5067 ms 526092 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9708 KB Output is correct
5 Correct 7 ms 9744 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 7 ms 9724 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 7 ms 9776 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9708 KB Output is correct
5 Correct 7 ms 9744 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 7 ms 9724 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 7 ms 9776 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9724 KB Output is correct
16 Correct 6 ms 9736 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9736 KB Output is correct
21 Correct 7 ms 9764 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 5 ms 9628 KB Output is correct
24 Correct 5 ms 9724 KB Output is correct
25 Correct 6 ms 9728 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9708 KB Output is correct
5 Correct 7 ms 9744 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 7 ms 9724 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 7 ms 9776 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9724 KB Output is correct
16 Correct 6 ms 9736 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9736 KB Output is correct
21 Correct 7 ms 9764 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 5 ms 9628 KB Output is correct
24 Correct 5 ms 9724 KB Output is correct
25 Correct 6 ms 9728 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 8 ms 9868 KB Output is correct
30 Correct 6 ms 9812 KB Output is correct
31 Correct 6 ms 9740 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 7 ms 9676 KB Output is correct
34 Correct 7 ms 9812 KB Output is correct
35 Correct 7 ms 9812 KB Output is correct
36 Correct 7 ms 9812 KB Output is correct
37 Correct 6 ms 9800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9708 KB Output is correct
5 Correct 7 ms 9744 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 7 ms 9724 KB Output is correct
8 Correct 7 ms 9684 KB Output is correct
9 Correct 7 ms 9776 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9724 KB Output is correct
16 Correct 6 ms 9736 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 5 ms 9684 KB Output is correct
20 Correct 6 ms 9736 KB Output is correct
21 Correct 7 ms 9764 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 5 ms 9628 KB Output is correct
24 Correct 5 ms 9724 KB Output is correct
25 Correct 6 ms 9728 KB Output is correct
26 Correct 6 ms 9684 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 6 ms 9684 KB Output is correct
29 Correct 8 ms 9868 KB Output is correct
30 Correct 6 ms 9812 KB Output is correct
31 Correct 6 ms 9740 KB Output is correct
32 Correct 6 ms 9684 KB Output is correct
33 Correct 7 ms 9676 KB Output is correct
34 Correct 7 ms 9812 KB Output is correct
35 Correct 7 ms 9812 KB Output is correct
36 Correct 7 ms 9812 KB Output is correct
37 Correct 6 ms 9800 KB Output is correct
38 Correct 91 ms 13216 KB Output is correct
39 Correct 202 ms 24688 KB Output is correct
40 Correct 62 ms 12484 KB Output is correct
41 Correct 31 ms 11124 KB Output is correct
42 Correct 51 ms 12548 KB Output is correct
43 Correct 27 ms 11192 KB Output is correct
44 Correct 12 ms 10068 KB Output is correct
45 Correct 47 ms 16292 KB Output is correct
46 Correct 47 ms 16264 KB Output is correct
47 Correct 64 ms 19964 KB Output is correct
48 Correct 65 ms 19972 KB Output is correct
49 Correct 50 ms 16500 KB Output is correct
50 Correct 48 ms 16284 KB Output is correct
51 Correct 42 ms 16476 KB Output is correct
52 Correct 40 ms 17296 KB Output is correct
53 Correct 12 ms 10196 KB Output is correct
54 Correct 54 ms 16232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 9 ms 9812 KB Output is correct
6 Correct 5 ms 9716 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9736 KB Output is correct
13 Correct 21 ms 10184 KB Output is correct
14 Correct 27 ms 10452 KB Output is correct
15 Correct 23 ms 10316 KB Output is correct
16 Correct 60 ms 16972 KB Output is correct
17 Correct 150 ms 23668 KB Output is correct
18 Correct 406 ms 46592 KB Output is correct
19 Correct 62 ms 17076 KB Output is correct
20 Correct 65 ms 16260 KB Output is correct
21 Correct 62 ms 16460 KB Output is correct
22 Correct 128 ms 25544 KB Output is correct
23 Correct 104 ms 25592 KB Output is correct
24 Correct 106 ms 23696 KB Output is correct
25 Correct 104 ms 23820 KB Output is correct
26 Correct 107 ms 25404 KB Output is correct
27 Correct 134 ms 22180 KB Output is correct
28 Correct 139 ms 26948 KB Output is correct
29 Correct 146 ms 25208 KB Output is correct
30 Correct 80 ms 23688 KB Output is correct
31 Correct 82 ms 23496 KB Output is correct
32 Correct 101 ms 22892 KB Output is correct
33 Correct 94 ms 23368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9744 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 12 ms 9760 KB Output is correct
5 Correct 24 ms 9776 KB Output is correct
6 Correct 6 ms 9804 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 90 ms 13564 KB Output is correct
10 Correct 203 ms 24488 KB Output is correct
11 Correct 10 ms 9812 KB Output is correct
12 Correct 43 ms 10760 KB Output is correct
13 Correct 141 ms 55520 KB Output is correct
14 Correct 172 ms 69676 KB Output is correct
15 Execution timed out 5067 ms 526092 KB Time limit exceeded
16 Halted 0 ms 0 KB -