답안 #890884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890884 2023-12-22T04:53:32 Z vjudge1 Jail (JOI22_jail) C++17
0 / 100
5000 ms 5724 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 120000;

vector<int> g[N+1];
int n;

/*
struct Fenwick{
	vector<int> fenw;
	int n;
	
	Fenwick(int sz){
		n = sz;
		fenw.resize(n+5, 0);
	};
	
	void add(int i, int x){
		for(; i <= n; i+= i & -i){
			fenw[i]+= x;
		}
	}
	int pref(int i){
		int s = 0;
		for(; i > 0; i-= i & -i){
			s+= fenw[i];
		}
		return s;
	}
	int sum(int l, int r){
		return pref(r) - pref(l-1);
	}
	
};

*/
void cl(){
	for(int i = 1;i <= n; i++) g[i].clear();
}






void solve(){
	 cin >> n;
	for(int i = 1;i < n; i++){
		int a, b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int q; cin >> q;
	vector< pair<int, int> > query(q);
	for(int i = 0;i < q; i++){
		cin >> query[i].ff >> query[i].ss;
	}
	vector<int> p(q);
	for(int i = 0;i < q; i++) p[i] = i;
	do{
		vector<int> used(n+1, 0);
		for(int i : p){
			used[query[i].ff]++;
		}
		int ok = 1;
		for(int i : p){
			used[query[i].ff]--;
			for(int j = min(query[i].ff, query[i].ss); j <= max(query[i].ff, query[i].ss); j++){
				if(used[j]){
					ok = 0;
					break;
				}
			}
			
			used[query[i].ss]++;
		}
		if(ok){
			cout << "Yes";
			return;
		}
	}while(next_permutation(all(p)));
	cout << "No";
}


signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t; cin >> t;
	while(t--){
		solve();
		cout << '\n';
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3168 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 7 ms 4184 KB Output is correct
5 Correct 16 ms 5724 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 4 ms 3420 KB Output is correct
8 Execution timed out 5060 ms 3164 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Incorrect 2 ms 3360 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Incorrect 2 ms 3360 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Incorrect 2 ms 3360 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Incorrect 2 ms 3360 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3172 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 1 ms 3164 KB Output is correct
5 Execution timed out 5045 ms 3584 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3168 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 7 ms 4184 KB Output is correct
5 Correct 16 ms 5724 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 4 ms 3420 KB Output is correct
8 Execution timed out 5060 ms 3164 KB Time limit exceeded
9 Halted 0 ms 0 KB -