제출 #291651

#제출 시각아이디문제언어결과실행 시간메모리
291651_7_7_Simurgh (IOI17_simurgh)C++14
30 / 100
1164 ms3832 KiB
#include "simurgh.h"
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 512;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;

vi g[N];
int id[N][N], m, d[N], par[N], p[N*N];
set < int > q, qq, bad, good;
bool was[N];
            	
void dfs (int v) {
	was[v] = 1;
	for (auto to : g[v])
		if (!was[to]) {
			q.insert(id[v][to]);
			d[to] = d[v] + 1;
			dfs(to);
			par[to] = v;
		}	
}

int get (int x) {
	vi cur;
	for (auto y : qq)
		if (y != x)
			cur.pb(y);

	for (auto y : q)
		if (!qq.count(y))
			cur.pb(y);

	return count_common_roads(cur);
}


vi find_roads(int n, vi u, vi v) {		
	m = sz(v);

	for (int i = 0; i < m; ++i) {
		g[v[i]].pb(u[i]);
		g[u[i]].pb(v[i]);
		id[v[i]][u[i]] = id[u[i]][v[i]] = i;
	}	

	dfs(0);
	
	for (int i = 0; i < m; ++i)
		p[i] = i;
	random_shuffle(p, p + m);

	for (int j = 0; j < m; ++j) {
		int i = p[j];
		if (q.count(i) || bad.count(i) || good.count(i))
			continue;
		qq.clear();
		qq.insert(i);
		if (d[v[i]] < d[u[i]])
			swap(v[i], u[i]);

	   	int Good = -1, Bad = -1;
	   	while (v[i] != u[i]) {
	   		qq.insert(id[v[i]][par[v[i]]]);
	   		if (bad.count(id[v[i]][par[v[i]]]))
	   			Bad = id[v[i]][par[v[i]]];

			if (good.count(id[v[i]][par[v[i]]]))
				Good = id[v[i]][par[v[i]]];

	   		v[i] = par[v[i]];
	   	}

	   	vpii res;
	   	for (auto x : qq) {
	   		if (bad.count(x) || good.count(x))
	   			continue;

			res.pb(mp(get(x), x));
	   	}
	   	
	   	sort(all(res));
	   	if (res[0].f == res.back().f) {
	   		if (Bad != -1) {
	   			if (get(Bad) == res.back().f) {
	   				for (auto y : qq)
	   					if (!good.count(y))
	   						bad.insert(y);
	   			} else {
	   				for (auto y : qq)
	   					if (!bad.count(y))
	   						good.insert(y);
	   			}
	   		} else if (Good != -1) {
	   			if (get(Good) == res.back().f) {
	   				for (auto y : qq)
	   					if (!bad.count(y))
	   						good.insert(y);	   			
	   			} else {
	   				for (auto y : qq)
	   					if (!good.count(y))
	   						bad.insert(y);	   					
	   			}
	   		} else {
	   			for (auto y : qq)
	   				if (!good.count(y))
	   					bad.insert(y);	   						   			   		
	   		}
	   	} else {
	   		for (auto y : res)
	   			if (y.f == res[0].f) 
	   				good.insert(y.s);
	   			else
	   				bad.insert(y.s);
	   	}
	}
	vi ans;
	for (int i = 0; i < m; ++i)
		if (!bad.count(i))
			good.insert(i);	

	for (auto x : good)
		ans.pb(x);

	return ans;
}

                
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...