Submission #132215

# Submission time Handle Problem Language Result Execution time Memory
132215 2019-07-18T13:23:26 Z MoNsTeR_CuBe Simurgh (IOI17_simurgh) C++17
0 / 100
2 ms 352 KB
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;

vector< int > U;

int getParents(int a){
	if(U[a] == a) return a;
	else return U[a] = getParents(U[a]);
}

void Union(int a, int b){
	U[getParents(a)] = getParents(b);
}

int makeBetter(vector< tuple<int, int, int> > &golden, vector< tuple<int, int, int> > &rem, int start, int n){
	
	for(int i = 0; i < n-1; i++){
		for(int j = 0; j < n;j++){
			U[j] = j;
		}
		vector< tuple<int, int, int> > tempo;
		
		vector< int > ans;
		
		for(int j = 0; j < n-1; j++){
			if(j == i) continue;
			assert(getParents(get<0>(golden[j])) != getParents(get<1>(golden[j])));
			
			Union(get<0>(golden[j]), get<1>(golden[j]));
			tempo.push_back(golden[j]);
			ans.push_back(get<2>(golden[i]));
		}
		for(int j = 0; j < (int)rem.size(); j++){
			if(getParents(get<0>(rem[j])) == getParents(get<1>(rem[j]))) continue;
			ans.push_back(get<2>(golden[i]));
			
			int x = count_common_roads(ans);
			
			if(x > start){
				
				golden = tempo;
				golden.push_back(rem[j]);
				
				swap(rem[j], rem.back());
				rem.pop_back();
				
				rem.push_back(golden[i]);
				
				return x;
			}
			ans.pop_back();
		}
	}
	return start;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	U.resize(n);
	for(int i = 0; i < n; i++){
		U[i] = i;
	}
	
	vector< tuple<int, int, int> > golden;
	
	vector< tuple<int, int, int> > rem;
	
	for(int i = 0; i < (int)u.size(); i++){
		if(getParents(u[i]) == getParents(v[i])){
			rem.push_back(make_tuple(u[i], v[i], i));
			continue;
		} 
		
		golden.push_back(make_tuple(u[i], v[i], i));
		
		Union(u[i], v[i]);
	}
	
	vector< int > ans;
	
	for(int i = 0; i < n-1; i++){
		ans.push_back(get<2>(golden[i]));
	}
	
	int start = count_common_roads(ans);
	
	while(start < n-1){
		start = makeBetter(golden, rem, start,n);
	}
	
	ans.clear();
	
	for(int i = 0; i < n-1; i++){
		ans.push_back(get<2>(golden[i]));
	}
	
	return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB correct
2 Incorrect 2 ms 352 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB WA in grader: NO
2 Halted 0 ms 0 KB -