답안 #631926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631926 2022-08-19T07:32:11 Z S2speed Jail (JOI22_jail) C++17
61 / 100
5000 ms 49996 KB
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("Ofast")

typedef long long ll;
typedef pair<ll , ll> pll;

const ll maxn = 2e5 + 17 , inf = 2e16;

vector<ll> adj[maxn];
ll jad[maxn][20] , bt[maxn] , ft[maxn] , tme , dis[maxn] , dep = 0;

void jDFS(ll r , ll par){
	bt[r] = tme++;
	dis[r] = dep++;
	jad[r][0] = par;
	for(ll j = 1 ; j < 20 ; j++){
		if(jad[r][j - 1] == -1) break;
		jad[r][j] = jad[jad[r][j - 1]][j - 1];
	}
	for(auto i : adj[r]){
		if(i == par) continue;
		jDFS(i , r);
	}
	ft[r] = tme;
	dep--;
	return;
}

ll find_jad(ll v , ll d){
	d = dis[v] - d;
	for(ll j = 19 ; ~j ; j--){
		if(d & (1 << j)){
			v = jad[v][j];
		}
	}
	return v;
}

bool too_masir(ll v , ll u , ll k){
	bool zv = (bt[v] >= bt[k] && ft[v] <= ft[k]) , zu = (bt[u] >= bt[k] && ft[u] <= ft[k]);
	if(!zv && !zu) return false;
	if(zv ^ zu) return true;
	ll hv = find_jad(v , dis[k] + 1) , hu = find_jad(u , dis[k] + 1);
	return (hv != hu);
}

ll a[maxn] , b[maxn] , d[maxn];
vector<ll> jda[maxn];
priority_queue<pll , vector<pll> , greater<pll>> pq;

void solve(){
	while(!pq.empty()) pq.pop();
	tme = 0;
	ll n;
	cin>>n;
	for(ll i = 0 ; i < n ; i++){
		adj[i].clear(); jda[i].clear(); d[i] = 0;
		for(ll j = 0 ; j < 20 ; j++) jad[i][j] = -1;
	}
	for(ll i = 1 ; i < n ; i++){
		ll v , u;
		cin>>v>>u; v--; u--;
		adj[v].push_back(u); adj[u].push_back(v);
	}
	jDFS(0 , -1);
	ll m;
	cin>>m;
	for(ll i = 0 ; i < m ; i++){
		cin>>a[i]>>b[i]; a[i]--; b[i]--;
	}
	for(ll i = 0 ; i < m ; i++){
		for(ll j = 0 ; j < m ; j++){
			if(j == i) continue;
			if(too_masir(a[i] , b[i] , a[j])){
				jda[i].push_back(j); d[j]++;
			}
			if(too_masir(a[i] , b[i] , b[j])){
				jda[j].push_back(i); d[i]++;
			}
		}
	}
	for(ll i = 0 ; i < m ; i++){
		pq.push({d[i] , i});
	}
	while(!pq.empty()){
		pll p = pq.top(); pq.pop();
		ll v = p.second;
		if(d[v] != p.first) continue;
		if(d[v] != 0){
			cout<<"No\n";
			return;
		}
		for(auto i : jda[v]){
			d[i]--;
			pq.push({d[i] , i});
		}
	}
	cout<<"Yes\n";
	return;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	ll T;
	cin>>T;
	while(T--) solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 6 ms 9720 KB Output is correct
4 Correct 18 ms 10068 KB Output is correct
5 Correct 21 ms 10420 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9864 KB Output is correct
8 Correct 23 ms 10384 KB Output is correct
9 Correct 615 ms 20568 KB Output is correct
10 Correct 128 ms 49996 KB Output is correct
11 Correct 13 ms 9868 KB Output is correct
12 Correct 197 ms 10872 KB Output is correct
13 Execution timed out 5081 ms 47972 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 7 ms 9752 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 6 ms 9860 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9864 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 7 ms 9800 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 7 ms 9752 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 6 ms 9860 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9864 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 7 ms 9800 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9740 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9744 KB Output is correct
16 Correct 8 ms 9812 KB Output is correct
17 Correct 6 ms 9860 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 6 ms 9856 KB Output is correct
21 Correct 7 ms 9812 KB Output is correct
22 Correct 6 ms 9860 KB Output is correct
23 Correct 5 ms 9716 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 7 ms 9812 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 5 ms 9684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 7 ms 9752 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 6 ms 9860 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9864 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 7 ms 9800 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9740 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9744 KB Output is correct
16 Correct 8 ms 9812 KB Output is correct
17 Correct 6 ms 9860 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 6 ms 9856 KB Output is correct
21 Correct 7 ms 9812 KB Output is correct
22 Correct 6 ms 9860 KB Output is correct
23 Correct 5 ms 9716 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 7 ms 9812 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 5 ms 9684 KB Output is correct
29 Correct 23 ms 10316 KB Output is correct
30 Correct 8 ms 9812 KB Output is correct
31 Correct 9 ms 9936 KB Output is correct
32 Correct 7 ms 9812 KB Output is correct
33 Correct 7 ms 9812 KB Output is correct
34 Correct 9 ms 9824 KB Output is correct
35 Correct 12 ms 10100 KB Output is correct
36 Correct 10 ms 9844 KB Output is correct
37 Correct 10 ms 9856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 7 ms 9752 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 6 ms 9860 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9864 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 6 ms 9940 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 7 ms 9800 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9740 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 6 ms 9744 KB Output is correct
16 Correct 8 ms 9812 KB Output is correct
17 Correct 6 ms 9860 KB Output is correct
18 Correct 6 ms 9812 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 6 ms 9856 KB Output is correct
21 Correct 7 ms 9812 KB Output is correct
22 Correct 6 ms 9860 KB Output is correct
23 Correct 5 ms 9716 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 7 ms 9812 KB Output is correct
26 Correct 6 ms 9812 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 5 ms 9684 KB Output is correct
29 Correct 23 ms 10316 KB Output is correct
30 Correct 8 ms 9812 KB Output is correct
31 Correct 9 ms 9936 KB Output is correct
32 Correct 7 ms 9812 KB Output is correct
33 Correct 7 ms 9812 KB Output is correct
34 Correct 9 ms 9824 KB Output is correct
35 Correct 12 ms 10100 KB Output is correct
36 Correct 10 ms 9844 KB Output is correct
37 Correct 10 ms 9856 KB Output is correct
38 Correct 633 ms 20552 KB Output is correct
39 Correct 103 ms 49924 KB Output is correct
40 Correct 212 ms 14620 KB Output is correct
41 Correct 111 ms 12408 KB Output is correct
42 Correct 140 ms 14760 KB Output is correct
43 Correct 33 ms 12364 KB Output is correct
44 Correct 54 ms 10624 KB Output is correct
45 Correct 68 ms 38112 KB Output is correct
46 Correct 73 ms 37960 KB Output is correct
47 Correct 73 ms 40736 KB Output is correct
48 Correct 70 ms 40720 KB Output is correct
49 Correct 73 ms 38140 KB Output is correct
50 Correct 67 ms 38076 KB Output is correct
51 Correct 61 ms 38936 KB Output is correct
52 Correct 65 ms 38912 KB Output is correct
53 Correct 70 ms 11992 KB Output is correct
54 Correct 81 ms 38624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9728 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 13 ms 9860 KB Output is correct
6 Correct 5 ms 9744 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9724 KB Output is correct
10 Correct 7 ms 9724 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 9 ms 9812 KB Output is correct
13 Correct 51 ms 10444 KB Output is correct
14 Correct 39 ms 10660 KB Output is correct
15 Correct 47 ms 10464 KB Output is correct
16 Correct 2044 ms 39256 KB Output is correct
17 Execution timed out 5050 ms 40732 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9724 KB Output is correct
3 Correct 6 ms 9720 KB Output is correct
4 Correct 18 ms 10068 KB Output is correct
5 Correct 21 ms 10420 KB Output is correct
6 Correct 7 ms 9812 KB Output is correct
7 Correct 6 ms 9864 KB Output is correct
8 Correct 23 ms 10384 KB Output is correct
9 Correct 615 ms 20568 KB Output is correct
10 Correct 128 ms 49996 KB Output is correct
11 Correct 13 ms 9868 KB Output is correct
12 Correct 197 ms 10872 KB Output is correct
13 Execution timed out 5081 ms 47972 KB Time limit exceeded
14 Halted 0 ms 0 KB -