#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;
int perform_experiment(vector<int> E);
map<pair<int,int>,int> mp;
int n , was[N] , p[N];
vector<int> g[N];
int gett(int x){
	if(p[x] == x) return x;
	return p[x] = gett(p[x]);
}
void merge(int a, int b){
	a = gett(a);
	b = gett(b);
	if(a == b) return;
	p[a] = b;
}
void get(int a , int b){
	if(mp[{a,b}] || mp[{b,a}]) return;
	mp[{a,b}] = mp[{b,a}] = 1;
	vector<int> E(n , n);
	E[a] = -1; E[b] = -1;
	int x = perform_experiment(E);
	E[a] = 0; E[b] = 0;
	int y = perform_experiment(E);
	if(x == y) merge(a,b);
}
void dfs(int v, int p){
	was[v] = 1;
	for(int to : g[v]){
		get(v,to);
		if(was[to] == 0) dfs(to,v);
	}
}
vector<int> find_colours(int N, vector<int> X, vector<int> Y) {
	n = N;
	for(int i = 0; i < n; i++) p[i] = i;
	for(int i = 0; i < X.size(); i++){		
		g[X[i]].push_back(Y[i]);
		g[Y[i]].push_back(X[i]);
	}
	for(int i = 0; i < n; i++){
		if(was[i] == 0){
			dfs(i,-1);
		}
	}
	vector<int> G;
	for(int i = 0; i < n; i++) G.push_back(gett(p[i]));
	return G;
}
	
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |