답안 #1041062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041062 2024-08-01T14:35:59 Z ReLice 열쇠 (IOI21_keys) C++17
100 / 100
589 ms 83648 KB
#include <bits/stdc++.h>
#define ll int
#define pb push_back
#define vll vector<ll>
#define fr first
#define sc second
#define ins insert
#define sz size()
using namespace std;
const int N = 3e5 + 7;
const int inf = 1e9;
vector<vector<pair<ll,ll>>> g(N);
int p[N];
vll have(N,0);
vll vis(N,0);
ll cen[N];
vector<ll> r;
vector<vll> need(N);
vector<vll> cmp(N);
vll er,er2;
int n;
bool merge(ll a,ll b){
	a=p[a],b=p[b];
	cen[a]=cen[b];
	if(a==b)return false;
	if(cmp[a].sz>cmp[b].sz)swap(a,b);
	for(auto i : cmp[a]){
		cmp[b].pb(i);
		p[i]=b;
	}
	return true;
}
ll bfs(ll v){
	queue<ll> q;
	q.push(v);
	while(q.sz){
		ll x=q.front();
		q.pop();
		if(vis[x])continue;
		if(!have[r[x]]){
			for(auto i : need[r[x]]){
				if(p[x]!=p[i])return p[i];
				q.push(i);
			}
		}
		vis[x]=have[r[x]]=1;
		er.pb(x);
		for(auto i : g[x]){
			ll to=i.fr,key=i.sc;
			if(have[key]==0){
				need[key].pb(to);
				er2.pb(key);
			}else{
				if(p[to]!=p[x])return p[to];
				q.push(to);
			}
		}
	}
	return -1;
}
void cl(){
	for(auto i : er){
		have[r[i]]=vis[i]=0;
	}
	for(auto i : er2) need[i].clear();
	er.clear();
	er2.clear();
}

vector<int> find_reachable(vector<int> R, vector<int> u, vector<int> v, vector<int> c) {
	
	r=R;
	n = r.size();
	
	int m=u.size();
	
	for(int i=0;i<m;i++){
		g[u[i]].pb({v[i],c[i]});
		g[v[i]].pb({u[i],c[i]});
	}
	
	vector<int> ans(n,0);
	int mn=inf;
	set<int> st;
	for(int i=0;i<n;i++){
		cmp[i].pb(i);
		p[i]=i;
		cen[i]=i;
	}
	
	while(true){
		vll to(n,0);
		bool f=0;
		
		for(int i=0;i<n;i++){
			if(p[i]!=i) continue;
			
			to[i]=bfs(cen[i]);
			if(to[i]>=0)f=1;
			
			cl();
		}
		
		
		if(!f)break;
		for(int i=0;i<n;i++){
			if(p[i]!=i || to[i]==-1) continue;
			
			ll v=p[to[i]];
			
			if(p[i]==v)continue;
			
			merge(i,v);
		}
	}
	for(int i=0;i<n;i++){
		if(i!=p[i])continue;
		if(p[i]==i)bfs(cen[i]);
		
		for(auto j : er)ans[j]=er.sz;
		
		if(p[i]==i){
			mn=min(mn,ans[cen[i]]);
		}
		cl();
	}
	
	for(int i=0;i<n;i++){
		if(ans[i]==mn)ans[i]=1;
		else ans[i]=0;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25944 KB Output is correct
2 Correct 5 ms 25944 KB Output is correct
3 Correct 6 ms 25948 KB Output is correct
4 Correct 7 ms 25976 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 6 ms 25948 KB Output is correct
7 Correct 6 ms 25948 KB Output is correct
8 Correct 6 ms 25948 KB Output is correct
9 Correct 6 ms 25948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25944 KB Output is correct
2 Correct 5 ms 25944 KB Output is correct
3 Correct 6 ms 25948 KB Output is correct
4 Correct 7 ms 25976 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 6 ms 25948 KB Output is correct
7 Correct 6 ms 25948 KB Output is correct
8 Correct 6 ms 25948 KB Output is correct
9 Correct 6 ms 25948 KB Output is correct
10 Correct 6 ms 25948 KB Output is correct
11 Correct 6 ms 25948 KB Output is correct
12 Correct 6 ms 25948 KB Output is correct
13 Correct 5 ms 25948 KB Output is correct
14 Correct 6 ms 25944 KB Output is correct
15 Correct 6 ms 25864 KB Output is correct
16 Correct 5 ms 25996 KB Output is correct
17 Correct 7 ms 25988 KB Output is correct
18 Correct 5 ms 25944 KB Output is correct
19 Correct 6 ms 25756 KB Output is correct
20 Correct 5 ms 25948 KB Output is correct
21 Correct 5 ms 25948 KB Output is correct
22 Correct 6 ms 25948 KB Output is correct
23 Correct 6 ms 25988 KB Output is correct
24 Correct 5 ms 25948 KB Output is correct
25 Correct 6 ms 25944 KB Output is correct
26 Correct 5 ms 25944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25944 KB Output is correct
2 Correct 5 ms 25944 KB Output is correct
3 Correct 6 ms 25948 KB Output is correct
4 Correct 7 ms 25976 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 6 ms 25948 KB Output is correct
7 Correct 6 ms 25948 KB Output is correct
8 Correct 6 ms 25948 KB Output is correct
9 Correct 6 ms 25948 KB Output is correct
10 Correct 6 ms 25948 KB Output is correct
11 Correct 6 ms 25948 KB Output is correct
12 Correct 6 ms 25948 KB Output is correct
13 Correct 5 ms 25948 KB Output is correct
14 Correct 6 ms 25944 KB Output is correct
15 Correct 6 ms 25864 KB Output is correct
16 Correct 5 ms 25996 KB Output is correct
17 Correct 7 ms 25988 KB Output is correct
18 Correct 5 ms 25944 KB Output is correct
19 Correct 6 ms 25756 KB Output is correct
20 Correct 5 ms 25948 KB Output is correct
21 Correct 5 ms 25948 KB Output is correct
22 Correct 6 ms 25948 KB Output is correct
23 Correct 6 ms 25988 KB Output is correct
24 Correct 5 ms 25948 KB Output is correct
25 Correct 6 ms 25944 KB Output is correct
26 Correct 5 ms 25944 KB Output is correct
27 Correct 8 ms 26204 KB Output is correct
28 Correct 7 ms 26208 KB Output is correct
29 Correct 7 ms 26208 KB Output is correct
30 Correct 6 ms 25952 KB Output is correct
31 Correct 6 ms 25952 KB Output is correct
32 Correct 6 ms 25952 KB Output is correct
33 Correct 6 ms 25948 KB Output is correct
34 Correct 7 ms 25952 KB Output is correct
35 Correct 6 ms 25952 KB Output is correct
36 Correct 6 ms 26208 KB Output is correct
37 Correct 6 ms 26268 KB Output is correct
38 Correct 6 ms 26208 KB Output is correct
39 Correct 7 ms 26244 KB Output is correct
40 Correct 6 ms 25948 KB Output is correct
41 Correct 6 ms 26004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25944 KB Output is correct
2 Correct 5 ms 25944 KB Output is correct
3 Correct 6 ms 25948 KB Output is correct
4 Correct 7 ms 25976 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 6 ms 25948 KB Output is correct
7 Correct 6 ms 25948 KB Output is correct
8 Correct 6 ms 25948 KB Output is correct
9 Correct 6 ms 25948 KB Output is correct
10 Correct 149 ms 55340 KB Output is correct
11 Correct 144 ms 71612 KB Output is correct
12 Correct 38 ms 32908 KB Output is correct
13 Correct 236 ms 60364 KB Output is correct
14 Correct 112 ms 71104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25944 KB Output is correct
2 Correct 5 ms 25944 KB Output is correct
3 Correct 6 ms 25948 KB Output is correct
4 Correct 7 ms 25976 KB Output is correct
5 Correct 8 ms 25944 KB Output is correct
6 Correct 6 ms 25948 KB Output is correct
7 Correct 6 ms 25948 KB Output is correct
8 Correct 6 ms 25948 KB Output is correct
9 Correct 6 ms 25948 KB Output is correct
10 Correct 6 ms 25948 KB Output is correct
11 Correct 6 ms 25948 KB Output is correct
12 Correct 6 ms 25948 KB Output is correct
13 Correct 5 ms 25948 KB Output is correct
14 Correct 6 ms 25944 KB Output is correct
15 Correct 6 ms 25864 KB Output is correct
16 Correct 5 ms 25996 KB Output is correct
17 Correct 7 ms 25988 KB Output is correct
18 Correct 5 ms 25944 KB Output is correct
19 Correct 6 ms 25756 KB Output is correct
20 Correct 5 ms 25948 KB Output is correct
21 Correct 5 ms 25948 KB Output is correct
22 Correct 6 ms 25948 KB Output is correct
23 Correct 6 ms 25988 KB Output is correct
24 Correct 5 ms 25948 KB Output is correct
25 Correct 6 ms 25944 KB Output is correct
26 Correct 5 ms 25944 KB Output is correct
27 Correct 8 ms 26204 KB Output is correct
28 Correct 7 ms 26208 KB Output is correct
29 Correct 7 ms 26208 KB Output is correct
30 Correct 6 ms 25952 KB Output is correct
31 Correct 6 ms 25952 KB Output is correct
32 Correct 6 ms 25952 KB Output is correct
33 Correct 6 ms 25948 KB Output is correct
34 Correct 7 ms 25952 KB Output is correct
35 Correct 6 ms 25952 KB Output is correct
36 Correct 6 ms 26208 KB Output is correct
37 Correct 6 ms 26268 KB Output is correct
38 Correct 6 ms 26208 KB Output is correct
39 Correct 7 ms 26244 KB Output is correct
40 Correct 6 ms 25948 KB Output is correct
41 Correct 6 ms 26004 KB Output is correct
42 Correct 149 ms 55340 KB Output is correct
43 Correct 144 ms 71612 KB Output is correct
44 Correct 38 ms 32908 KB Output is correct
45 Correct 236 ms 60364 KB Output is correct
46 Correct 112 ms 71104 KB Output is correct
47 Correct 6 ms 25948 KB Output is correct
48 Correct 5 ms 25936 KB Output is correct
49 Correct 6 ms 25916 KB Output is correct
50 Correct 101 ms 68472 KB Output is correct
51 Correct 116 ms 70828 KB Output is correct
52 Correct 162 ms 59176 KB Output is correct
53 Correct 151 ms 58960 KB Output is correct
54 Correct 158 ms 58960 KB Output is correct
55 Correct 192 ms 57544 KB Output is correct
56 Correct 319 ms 74540 KB Output is correct
57 Correct 183 ms 68132 KB Output is correct
58 Correct 172 ms 83648 KB Output is correct
59 Correct 240 ms 75368 KB Output is correct
60 Correct 236 ms 74504 KB Output is correct
61 Correct 233 ms 75288 KB Output is correct
62 Correct 472 ms 68432 KB Output is correct
63 Correct 109 ms 61580 KB Output is correct
64 Correct 8 ms 26716 KB Output is correct
65 Correct 7 ms 26716 KB Output is correct
66 Correct 589 ms 68768 KB Output is correct
67 Correct 18 ms 30808 KB Output is correct
68 Correct 23 ms 33944 KB Output is correct
69 Correct 248 ms 75076 KB Output is correct
70 Correct 43 ms 42440 KB Output is correct
71 Correct 128 ms 74684 KB Output is correct
72 Correct 248 ms 75332 KB Output is correct
73 Correct 480 ms 68660 KB Output is correct