Submission #858315

# Submission time Handle Problem Language Result Execution time Memory
858315 2023-10-08T05:54:27 Z willychan Jail (JOI22_jail) C++14
21 / 100
5000 ms 600 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
const int N = 300;
int p[N];
bool havestuff[N];
vector<int> side[N];
vector<pair<int,int> > qu;
int n;
int dep[N];
void dfs(int cur){
	for(auto i : side[cur])	{
		if(p[i]) continue;
		p[i]=cur;
		dep[i]=dep[cur]+1;
		dfs(i);
	}
}
bool works(vector<int> &order){
	for(auto i : order){
		int a = qu[i].first;
		int b = qu[i].second;
		int og = b;
		havestuff[a]=0;
		while(a!=b){
			if(dep[a]>dep[b]) swap(a,b);
			if(havestuff[b]) return 0;
			b = p[b];
		}
		if(havestuff[b]) return 0;
		havestuff[og]=1;
	}
	return 1;
}

void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		side[i].clear();
		dep[i]=0;
		p[i]=0;
	}
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		side[a].push_back(b);
		side[b].push_back(a);
	}
	p[1]=1;
	dfs(1);
	int m;
	cin>>m;
	qu.resize(m);
	for(int i=0;i<m;i++) cin>>qu[i].first>>qu[i].second;
	vector<int> order(m);
	for(int i=0;i<m;i++) order[i]=i;
	do{
		for(int i=1;i<=n;i++) havestuff[i]=0;
		for(int i=0;i<m;i++) havestuff[qu[i].first]=1;
		if(works(order)){
			cout<<"Yes\n";
			return ;
		}
	}while(next_permutation(order.begin(),order.end()));
	cout<<"No\n";
	return ;
		
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int q;cin>>q;
	while(q--){
		solve();
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 14 ms 476 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Execution timed out 5044 ms 348 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 484 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 484 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 516 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 484 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 516 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Execution timed out 5050 ms 348 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 484 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 516 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Execution timed out 5050 ms 348 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 5084 ms 456 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 14 ms 476 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Execution timed out 5044 ms 348 KB Time limit exceeded
9 Halted 0 ms 0 KB -