Submission #814847

# Submission time Handle Problem Language Result Execution time Memory
814847 2023-08-08T10:31:11 Z Dan4Life Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 340 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];
}

vi find_roads(int N, vi u, vi v) {
	vi ans; m = sz(u); n = N; init(n);
	for(int i = 0; i < m; i++){
		if(vis[i]==1) continue; 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) 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 j = 0; j < sz(v); j++){
			w.pb(v[j]); mx = max(mx, {count_common_roads(w),j}); w.pop_back();
		}
		ans.pb(mx.second);
	}
	return ans;
}

Compilation message

simurgh.cpp: In function 'vi find_roads(int, vi, vi)':
simurgh.cpp:24:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   24 |   if(vis[i]==1) continue; init(n);
      |   ^~
simurgh.cpp:24:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   24 |   if(vis[i]==1) continue; init(n);
      |                           ^~~~
# 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 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 -