Submission #814840

# Submission time Handle Problem Language Result Execution time Memory
814840 2023-08-08T10:28:30 Z Dan4Life Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 368 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+10;
int m, p[mxN], sz[mxN];
bool vis[100000];
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];
}

vi find_roads(int n, vi u, vi v) {
	vi ans; m = sz(u); init(n);
	for(int i = 0; i < m; i++){
		if(vis[i]==1) continue;
		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) v.pb(j);
			else unionSet(u[j],v[j]), w.pb(j);
		}
		for(auto u : v) vis[u]=1;
		pair<int,int> mx = {0,0};
		for(int i = 0; i < sz(v); i++){
			w.pb(v[i]); mx = max(mx, {count_common_roads(w),i}); w.pop_back();
		}
		ans.pb(mx.second);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 368 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -