답안 #545183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545183 2022-04-03T21:10:16 Z inksamurai Jail (JOI22_jail) C++17
5 / 100
14 ms 588 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(s!=v and ids[v]!=-1){
				gr[ids[v]].pb(ids[s]);
			}
			if(s!=v and v!=t 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,0);
		}
	}
	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 Incorrect 14 ms 588 KB Output isn't correct
5 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 2 ms 400 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 1 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 2 ms 400 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Incorrect 2 ms 336 KB Output isn't correct
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 2 ms 400 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Incorrect 2 ms 336 KB Output isn't correct
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 2 ms 400 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Incorrect 2 ms 336 KB Output isn't correct
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 0 ms 212 KB Output is correct
5 Incorrect 8 ms 468 KB Output isn't correct
6 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 Incorrect 14 ms 588 KB Output isn't correct
5 Halted 0 ms 0 KB -