답안 #545187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545187 2022-04-03T21:22:10 Z inksamurai Jail (JOI22_jail) C++17
61 / 100
5000 ms 25556 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3x2WzQf ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

void slv(){
	int n;
	cin>>n;
	vec(vi) adj(n);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u-=1,v-=1;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int m;
	cin>>m;
	vi to(n,-1),ids(n,-1),idt(n,-1);
	rep(i,m){
		int s,t;
		cin>>s>>t;
		s-=1,t-=1;
		ids[s]=i;
		idt[t]=i;
		to[s]=t;
	}

	int s;
	vec(vi) gr(m);
	auto walk=[&](auto self,int v,int par,int t)->bool{
		bool type=0;
		for(auto u:adj[v]){
			if(u==par) continue;
			type=type or self(self,u,v,t);
		}
		type=type or v==t;
		if(type){
			if(ids[v]!=ids[s] and ids[v]!=-1){
				gr[ids[v]].pb(ids[s]);
			}
			if(idt[v]!=ids[s] and idt[v]!=-1){
				gr[ids[s]].pb(idt[v]);
			}
		}
		return type;
	};


	rep(v,n){
		if(ids[v]!=-1){
			s=v;
			walk(walk,v,-1,to[v]);
		}
	}

	vi usd(m,0),usd1(m,0);
	bool cyc=0;
	auto dfs=[&](auto self,int v)->void{
		usd[v]=1;
		usd1[v]=1;
		for(auto u:gr[v]){
			if(usd1[u]){
				cyc=1;
			}
			if(!usd[u]){
				self(self,u);
			}
		}
		usd1[v]=0;
	};

	// rep(v,m){
	// 	print(v);
	// 	for(auto u:gr[v]){
	// 		cout<<u<<" ";
	// 	}
	// 	cout<<"\n";
	// }

	rep(v,m){
		if(!usd[v]){
			dfs(dfs,v);
		}
	}
	cout<<(cyc?"No":"Yes")<<"\n";
}

signed main(){
_3x2WzQf;
	int t;
	cin>>t;
	rep(cs,t){
		slv();
	}
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 13 ms 340 KB Output is correct
5 Correct 28 ms 960 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 400 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 504 ms 3516 KB Output is correct
10 Correct 1777 ms 25208 KB Output is correct
11 Correct 8 ms 468 KB Output is correct
12 Correct 88 ms 928 KB Output is correct
13 Execution timed out 5052 ms 25556 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 2 ms 388 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 328 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 2 ms 388 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 328 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 7 ms 468 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 5 ms 336 KB Output is correct
32 Correct 3 ms 388 KB Output is correct
33 Correct 3 ms 380 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 5 ms 340 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 2 ms 388 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 328 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 7 ms 468 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 5 ms 336 KB Output is correct
32 Correct 3 ms 388 KB Output is correct
33 Correct 3 ms 380 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 5 ms 340 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 619 ms 3348 KB Output is correct
39 Correct 1514 ms 25292 KB Output is correct
40 Correct 564 ms 2056 KB Output is correct
41 Correct 536 ms 1328 KB Output is correct
42 Correct 278 ms 2084 KB Output is correct
43 Correct 98 ms 1392 KB Output is correct
44 Correct 69 ms 664 KB Output is correct
45 Correct 1770 ms 9116 KB Output is correct
46 Correct 1739 ms 8996 KB Output is correct
47 Correct 795 ms 16212 KB Output is correct
48 Correct 747 ms 16324 KB Output is correct
49 Correct 1086 ms 9188 KB Output is correct
50 Correct 1116 ms 9292 KB Output is correct
51 Correct 549 ms 11332 KB Output is correct
52 Correct 531 ms 11340 KB Output is correct
53 Correct 60 ms 1180 KB Output is correct
54 Correct 1402 ms 8812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 4 ms 380 KB Output is correct
13 Correct 44 ms 832 KB Output is correct
14 Correct 55 ms 1068 KB Output is correct
15 Correct 55 ms 936 KB Output is correct
16 Execution timed out 5045 ms 9552 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 13 ms 340 KB Output is correct
5 Correct 28 ms 960 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 400 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 504 ms 3516 KB Output is correct
10 Correct 1777 ms 25208 KB Output is correct
11 Correct 8 ms 468 KB Output is correct
12 Correct 88 ms 928 KB Output is correct
13 Execution timed out 5052 ms 25556 KB Time limit exceeded
14 Halted 0 ms 0 KB -