Submission #942580

# Submission time Handle Problem Language Result Execution time Memory
942580 2024-03-10T22:53:15 Z pcc Jail (JOI22_jail) C++17
10 / 100
1505 ms 334696 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll> 
const int mxn = 120010;vector<int> tree[mxn];int N,M;int vcnt,ecnt;int head[mxn*100],nid[mxn*100],to[mxn*100];pii arr[mxn];const int H = 20; namespace BUILD{	int newnode(){		return ++vcnt;	}	void add_edge(int a,int b){		ecnt++;		nid[ecnt] = head[a];		to[ecnt] = b;		head[a] = ecnt;	}	int par[mxn][H],dep[mxn];	int stree[mxn][H],etree[mxn][H];	int sleaf[mxn],eleaf[mxn];	void dfs(int now){		sleaf[now] = newnode();		eleaf[now] = newnode();		stree[now][0] = newnode();		etree[now][0] = newnode();		add_edge(etree[now][0],eleaf[now]);		add_edge(etree[now][0],eleaf[par[now][0]]);		add_edge(sleaf[now],stree[now][0]);		add_edge(sleaf[par[now][0]],stree[now][0]);		for(int i = 1;i<H;i++){			par[now][i] = par[par[now][i-1]][i-1];			stree[now][i] = newnode();			etree[now][i] = newnode();			add_edge(stree[now][i-1],stree[now][i]);			add_edge(stree[par[now][i-1]][i-1],stree[now][i]);			add_edge(etree[now][i],etree[now][i-1]);			add_edge(etree[now][i],etree[par[now][i-1]][i-1]);		}		/*		cerr<<now<<":"<<sleaf[now]<<' '<<eleaf[now]<<endl;;		for(int i = 0;i<H;i++)cerr<<stree[now][i]<<' ';cerr<<endl;		for(int i = 0;i<H;i++)cerr<<etree[now][i]<<' ';cerr<<endl; 	   */		for(auto nxt:tree[now]){			if(nxt == par[now][0])continue;			par[nxt][0] = now;			dep[nxt] = dep[now]+1;			dfs(nxt);		}		return;	}	void add(int a,int b,int id){		if(dep[a]<dep[b])swap(a,b);		int d = dep[a]-dep[b];		for(int i = H-1;i>=0;i--){			if(d&(1<<i)){				add_edge(stree[a][i],id);				add_edge(id,etree[a][i]);				a = par[a][i];			}		}		for(int i = H-1;i>=0;i--){			if(par[a][i] != par[b][i]){				add_edge(stree[a][i],id);				add_edge(stree[b][i],id);				add_edge(id,etree[a][i]);				add_edge(id,etree[b][i]);				a = par[a][i],b = par[b][i];			}		}		if(a != b){			add_edge(stree[a][0],id);			add_edge(id,etree[a][0]);		}		return;	}	void GO(){		par[1][0] = 1;		dfs(1);	}	void ADD_CON(){		for(int i = 1;i<=M;i++){			int a = arr[i].fs,b = arr[i].sc;			add(a,b,i);			add_edge(sleaf[a],i);			add_edge(i,sleaf[a]);			add_edge(eleaf[b],i);			add_edge(i,eleaf[b]);			/*			cerr<<"ADD:"<<endl;			cerr<<i<<":"<<a<<' '<<b<<' '<<sleaf[a]<<','<<eleaf[b]<<endl; 		   */		}		return;	}	void PRINT(){		for(int i = 1;i<=vcnt;i++){			cout<<i<<":";			for(int eid = head[i];eid;eid = nid[eid]){				cout<<to[eid]<<',';			}cout<<endl;		}	}	void init(){    for(int i =0;i<=vcnt;i++)head[i]=0;		dep[1] = 0;	}} namespace SCC{	int deg[mxn*100],low[mxn*100],idx[mxn*100],gid[mxn*100],cnt,gcnt;	int dp[mxn*100];	vector<int> st;	void dfs(int now){		idx[now] = low[now] = ++cnt;		st.push_back(now);		for(int eid = head[now];eid;eid = nid[eid]){			int nxt = to[eid];			if(gid[nxt])continue;			if(!idx[nxt]){				dfs(nxt);				low[now] = min(low[now],low[nxt]);			}			else low[now] = min(low[now],idx[nxt]);		}		if(idx[now] == low[now]){			gcnt++;			while(st.back() != now){				gid[st.back()] = gcnt;				st.pop_back();			}			gid[st.back()] = gcnt;			st.pop_back();		}		return;	}	void GO(){		for(int i = 1;i<=vcnt;i++){			if(!idx[i])dfs(i);		}		for(int i = 1;i<=M;i++){			dp[gid[i]]++;		}		if(*max_element(dp,dp+gcnt+1)>1){			cout<<"No\n";			return;		}		else cout<<"Yes\n";		return;	}	void init(){		for(int i = 1;i<=vcnt;i++){			gid[i] = dp[i] = idx[i] = low[i] = 0;		}        cnt=gcnt=0;		return;	}} void init(){	for(int i = 0;i<=N;i++){		tree[i].clear();	}	SCC::init();	BUILD::init();	vcnt = ecnt = 0;	return;} void solve(){	init();	cin>>N;	for(int i = 1;i<N;i++){		int a,b;		cin>>a>>b;		tree[a].push_back(b);		tree[b].push_back(a);	}	cin>>M;	for(int i = 1;i<=M;i++){		cin>>arr[i].fs>>arr[i].sc;	}	vcnt = M;	BUILD::GO();	BUILD::ADD_CON();	/*BUILD::PRINT();*/	SCC::GO();} int main(){	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);	int t;cin>>t;	while(t--)solve();}/*331 22 32 2 13 271 22 33 44 55 66 731 34 22 581 22 33 44 55 66 77 841 52 63 74 8*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25436 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 3 ms 25436 KB Output is correct
4 Correct 43 ms 25952 KB Output is correct
5 Correct 94 ms 26452 KB Output is correct
6 Correct 8 ms 26084 KB Output is correct
7 Correct 10 ms 25692 KB Output is correct
8 Correct 8 ms 25908 KB Output is correct
9 Correct 141 ms 39908 KB Output is correct
10 Correct 680 ms 220112 KB Output is correct
11 Correct 20 ms 25692 KB Output is correct
12 Correct 105 ms 26864 KB Output is correct
13 Correct 484 ms 229260 KB Output is correct
14 Correct 408 ms 229856 KB Output is correct
15 Correct 1182 ms 277976 KB Output is correct
16 Correct 1505 ms 334696 KB Output is correct
17 Correct 674 ms 229604 KB Output is correct
18 Correct 461 ms 230768 KB Output is correct
19 Correct 594 ms 231508 KB Output is correct
20 Correct 585 ms 231516 KB Output is correct
21 Correct 650 ms 280196 KB Output is correct
22 Correct 443 ms 224692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 25432 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Correct 8 ms 25692 KB Output is correct
5 Correct 8 ms 25692 KB Output is correct
6 Correct 8 ms 25688 KB Output is correct
7 Correct 7 ms 25692 KB Output is correct
8 Correct 8 ms 25692 KB Output is correct
9 Correct 8 ms 25808 KB Output is correct
10 Correct 8 ms 25692 KB Output is correct
11 Correct 7 ms 25692 KB Output is correct
12 Correct 7 ms 25692 KB Output is correct
13 Correct 5 ms 25692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 25432 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Correct 8 ms 25692 KB Output is correct
5 Correct 8 ms 25692 KB Output is correct
6 Correct 8 ms 25688 KB Output is correct
7 Correct 7 ms 25692 KB Output is correct
8 Correct 8 ms 25692 KB Output is correct
9 Correct 8 ms 25808 KB Output is correct
10 Correct 8 ms 25692 KB Output is correct
11 Correct 7 ms 25692 KB Output is correct
12 Correct 7 ms 25692 KB Output is correct
13 Correct 5 ms 25692 KB Output is correct
14 Correct 3 ms 25436 KB Output is correct
15 Correct 4 ms 25692 KB Output is correct
16 Correct 8 ms 25692 KB Output is correct
17 Correct 7 ms 25692 KB Output is correct
18 Correct 8 ms 25820 KB Output is correct
19 Correct 4 ms 25436 KB Output is correct
20 Incorrect 8 ms 25684 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 25432 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Correct 8 ms 25692 KB Output is correct
5 Correct 8 ms 25692 KB Output is correct
6 Correct 8 ms 25688 KB Output is correct
7 Correct 7 ms 25692 KB Output is correct
8 Correct 8 ms 25692 KB Output is correct
9 Correct 8 ms 25808 KB Output is correct
10 Correct 8 ms 25692 KB Output is correct
11 Correct 7 ms 25692 KB Output is correct
12 Correct 7 ms 25692 KB Output is correct
13 Correct 5 ms 25692 KB Output is correct
14 Correct 3 ms 25436 KB Output is correct
15 Correct 4 ms 25692 KB Output is correct
16 Correct 8 ms 25692 KB Output is correct
17 Correct 7 ms 25692 KB Output is correct
18 Correct 8 ms 25820 KB Output is correct
19 Correct 4 ms 25436 KB Output is correct
20 Incorrect 8 ms 25684 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 25432 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 7 ms 25692 KB Output is correct
4 Correct 8 ms 25692 KB Output is correct
5 Correct 8 ms 25692 KB Output is correct
6 Correct 8 ms 25688 KB Output is correct
7 Correct 7 ms 25692 KB Output is correct
8 Correct 8 ms 25692 KB Output is correct
9 Correct 8 ms 25808 KB Output is correct
10 Correct 8 ms 25692 KB Output is correct
11 Correct 7 ms 25692 KB Output is correct
12 Correct 7 ms 25692 KB Output is correct
13 Correct 5 ms 25692 KB Output is correct
14 Correct 3 ms 25436 KB Output is correct
15 Correct 4 ms 25692 KB Output is correct
16 Correct 8 ms 25692 KB Output is correct
17 Correct 7 ms 25692 KB Output is correct
18 Correct 8 ms 25820 KB Output is correct
19 Correct 4 ms 25436 KB Output is correct
20 Incorrect 8 ms 25684 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 25432 KB Output is correct
2 Correct 4 ms 25436 KB Output is correct
3 Correct 3 ms 25668 KB Output is correct
4 Correct 4 ms 25432 KB Output is correct
5 Correct 24 ms 25692 KB Output is correct
6 Correct 5 ms 25692 KB Output is correct
7 Correct 5 ms 25692 KB Output is correct
8 Correct 4 ms 25692 KB Output is correct
9 Correct 4 ms 25524 KB Output is correct
10 Correct 4 ms 25692 KB Output is correct
11 Correct 4 ms 25704 KB Output is correct
12 Correct 8 ms 25692 KB Output is correct
13 Incorrect 59 ms 26196 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 25436 KB Output is correct
2 Correct 4 ms 25432 KB Output is correct
3 Correct 3 ms 25436 KB Output is correct
4 Correct 43 ms 25952 KB Output is correct
5 Correct 94 ms 26452 KB Output is correct
6 Correct 8 ms 26084 KB Output is correct
7 Correct 10 ms 25692 KB Output is correct
8 Correct 8 ms 25908 KB Output is correct
9 Correct 141 ms 39908 KB Output is correct
10 Correct 680 ms 220112 KB Output is correct
11 Correct 20 ms 25692 KB Output is correct
12 Correct 105 ms 26864 KB Output is correct
13 Correct 484 ms 229260 KB Output is correct
14 Correct 408 ms 229856 KB Output is correct
15 Correct 1182 ms 277976 KB Output is correct
16 Correct 1505 ms 334696 KB Output is correct
17 Correct 674 ms 229604 KB Output is correct
18 Correct 461 ms 230768 KB Output is correct
19 Correct 594 ms 231508 KB Output is correct
20 Correct 585 ms 231516 KB Output is correct
21 Correct 650 ms 280196 KB Output is correct
22 Correct 443 ms 224692 KB Output is correct
23 Correct 4 ms 25432 KB Output is correct
24 Correct 4 ms 25432 KB Output is correct
25 Correct 7 ms 25692 KB Output is correct
26 Correct 8 ms 25692 KB Output is correct
27 Correct 8 ms 25692 KB Output is correct
28 Correct 8 ms 25688 KB Output is correct
29 Correct 7 ms 25692 KB Output is correct
30 Correct 8 ms 25692 KB Output is correct
31 Correct 8 ms 25808 KB Output is correct
32 Correct 8 ms 25692 KB Output is correct
33 Correct 7 ms 25692 KB Output is correct
34 Correct 7 ms 25692 KB Output is correct
35 Correct 5 ms 25692 KB Output is correct
36 Correct 3 ms 25436 KB Output is correct
37 Correct 4 ms 25692 KB Output is correct
38 Correct 8 ms 25692 KB Output is correct
39 Correct 7 ms 25692 KB Output is correct
40 Correct 8 ms 25820 KB Output is correct
41 Correct 4 ms 25436 KB Output is correct
42 Incorrect 8 ms 25684 KB Output isn't correct
43 Halted 0 ms 0 KB -