Submission #814895

# Submission time Handle Problem Language Result Execution time Memory
814895 2023-08-08T10:58:04 Z Dan4Life Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 212 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)5e2+2;
const int mxM = mxN*mxN/2;
int n, m, p[mxN], sz[mxN];
bool vis[mxM];
void init(int n){ for(int i = 0; i < n; i++) p[i]=i,sz[i]=1;}
int findSet(int i){return i==p[i]?i:p[i]=findSet(p[i]);}
bool isSameSet(int i, int j){return findSet(i)==findSet(j);}
void unionSet(int i, int j){
	int x = findSet(i), y = findSet(j);
	if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	p[y] = x; sz[x]+=sz[y];
}

int query(vector<int> &v){
	return count_common_roads(v);
}

vi find_roads(int N, vi u, vi v) {
	vi ans; m = sz(u); n = N;
	for(int i = 0; i < m; i++){
		init(n);
		vector<int> V, w; V.clear(); w.clear();
		for(int j = 0; j < m; j++){
			if(isSameSet(u[j],v[j])) continue;
			int x = findSet(u[i]), y = findSet(v[i]);
			if(x>y) swap(x,y);
			int x2 = findSet(u[j]), y2 = findSet(v[j]);
			if(x2>y2) swap(x2,y2);
			if(x==x2 and y==y2) continue;
			unionSet(u[j],v[j]), w.pb(j);
		}
		w.pb(i); int cur = query(w);
		w.pop_back(); bool ok = 1;
		for(int j = 0; j < m; j++){
			if(isSameSet(u[j],v[j]) or i==j) continue;
			int x = findSet(u[i]), y = findSet(v[i]);
			if(x>y) swap(x,y);
			int x2 = findSet(u[j]), y2 = findSet(v[j]);
			if(x2>y2) swap(x2,y2);
			if(x==x2 and y==y2){
				w.pb(j);
				if(query(w)>=cur) ok = 0; 
				break;
			}
		}
		if(ok) ans.pb(i);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Incorrect 1 ms 212 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -