제출 #250227

#제출 시각아이디문제언어결과실행 시간메모리
250227srvltSimurgh (IOI17_simurgh)C++14
51 / 100
192 ms6400 KiB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define SZ(x) (int)(x).size()

const int n0 = 243, m0 = 29000;
int N, M, used[n0], ch[m0], par[n0], sp[m0], same[m0];
int in[n0], out[n0], T, common;
vector <int> g[n0], V, U, query;

void dfs(int v) {
	used[v] = 1;
	in[v] = ++T;
	for (int i : g[v]) {
		int to = V[i] ^ U[i] ^ v;
		if (used[to]) continue;
		par[to] = i;
		query.pb(i);
		sp[i] =  1;
		dfs(to);
	}
	out[v] = T;
}

bool upper(int v, int u) {
	return in[v] <= in[u] && out[u] <= out[v];
}

void add(int x) {
	query.pb(x);
}

void del(int x) {
	for (int i = 0; i < SZ(query); i++) {
		if (query[i] == x) {
			query.erase(query.begin() + i);
			break;
		}
	}
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	memset(& ch, -1, sizeof(ch));
	N = n, M = u.size(), V = v, U = u;
	for (int i = 0; i < M; i++)
		g[v[i]].pb(i), g[u[i]].pb(i);
	dfs(0);
	vector <int> path;
	common = count_common_roads(query);
	for (int i = 0; i < M; i++) {
		if (sp[i]) continue;
		int a = v[i], b = u[i];
		if (upper(b, a)) swap(a, b);
		path.clear();
		while (b != a) {
			path.pb(par[b]);
			b = v[par[b]] ^ u[par[b]] ^ b;
		}
		add(i);
		for (int j : path) {
			if (ch[i] != -1 && ch[j] != -1) continue;
			del(j);
			int x = count_common_roads(query);
			if (x == common) {
				if (ch[j] != -1) ch[i] = ch[j];
				same[j] = 1;
			}	else {
				if (x == common - 1) {
					ch[i] = 0;
					ch[j] = 1;
				}
				if (x == common + 1) {
					ch[i] = 1;
					ch[j] = 0;
				}
			}
			add(j);
		}
		if (ch[i] == -1) ch[i] = 0;
		del(i);
		for (int j : path) {
			if (same[j]) ch[j] = ch[i];
			same[j] = 0;
		}
	}
	vector <int> res;
	for (int i = 0; i < M; i++) {
		if (ch[i] == -1) ch[i] = 1;
		if (ch[i] == 1) res.pb(i);
	}
	return res;
}
#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...