Submission #293090

# Submission time Handle Problem Language Result Execution time Memory
293090 2020-09-07T16:09:25 Z amoo_safar Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 512 KB
#include "simurgh.h"

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 500 + 10;

vector<pii> G[N], H[N];
int mk[N], E[N], par[N], dep[N];

vector<int> R;

void DFS1(int u, int d = 0){
	mk[u] = 1;
	dep[u] = d;
	for(auto [adj, id] : G[u]){
		if(!mk[adj]){
			R.pb(id);
			par[adj] = u;
			DFS1(adj, d + 1);
			E[adj] = id;
		}
	}
}
ll f;
map<pii, int> mp;
int Ask(int rm, int is){
	if(mp.count({rm, is})) return mp[{rm, is}];
	vector<int> R2 = R;
	for(auto &x : R2) if(x == rm) x = is;
	return mp[{rm, is}] = count_common_roads(R2);
}

int sta[N * N];

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	vector<int> r(n - 1);
	int m = u.size();
	for(int i = 0; i < m; i++){
		G[u[i]].pb({v[i], i});
		G[v[i]].pb({u[i], i});
	}
	DFS1(0, 0);
	f = count_common_roads(R);

	vector<int> X;
	for(int i = 0; i < m; i++){
		if(dep[u[i]] > dep[v[i]]) swap(u[i], v[i]);
		if(E[v[i]] == i) continue;
		X.clear();
		int nw = v[i];
		//cerr << '\n';
		while(nw != u[i]){
			//cerr << "# " << nw << '\n';
			X.pb(E[nw]);
			nw = par[nw];
		}
		int mn = f;
		bool flg = false;
		for(auto x : X){
			if(sta[x] && flg) continue;
			if(sta[x] == 1){
				mn = min(mn, Ask(x, i) - 1);
				flg = true;
			} else if(sta[x] == 2){
				mn = min(mn, Ask(x, i));
				flg = true;
			} else {
				mn = min(mn, Ask(x, i));
			}
		}
		if(flg){
			if(f == mn) sta[i] = 1;
			else sta[i] = 2;
			for(auto x : X){
				if(sta[x] == 0){
					if(Ask(x, i) == mn) sta[x] = 1;
					else sta[x] = 2;
				}
			}
		} else {
			bool f2 = false;
			for(auto x : X) if(mn != Ask(x, i)) f2 = true;
			if(f2){
				if(f == mn) sta[i] = 1;
				else sta[i] = 2;
				for(auto x : X){
					if(sta[x] == 0){
						if(Ask(x, i) == mn) sta[x] = 1;
						else sta[x] = 2;
					}
				}
			} else {
				sta[i] = 1;
				for(auto x : X) sta[x] = 1;
			}
		}
	}
	vector<int> res;
	for(int i = 0; i < m; i++) if(sta[i] != 1) res.pb(i);

	assert(((int) res.size()) == n - 1);
	return r;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB correct
2 Runtime error 1 ms 512 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -