답안 #291647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291647 2020-09-05T15:09:54 Z _7_7_ Simurgh (IOI17_simurgh) C++14
30 / 100
1203 ms 4232 KB
#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];
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) {
		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;
}

                
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 17 ms 512 KB correct
15 Correct 18 ms 512 KB correct
16 Correct 18 ms 512 KB correct
17 Correct 18 ms 512 KB correct
18 Correct 6 ms 512 KB correct
19 Correct 15 ms 512 KB correct
20 Correct 14 ms 512 KB correct
21 Correct 13 ms 512 KB correct
22 Correct 8 ms 512 KB correct
23 Correct 7 ms 512 KB correct
24 Correct 6 ms 512 KB correct
25 Correct 1 ms 512 KB correct
26 Correct 6 ms 512 KB correct
27 Correct 7 ms 512 KB correct
28 Correct 3 ms 512 KB correct
29 Correct 1 ms 512 KB correct
30 Correct 8 ms 512 KB correct
31 Correct 8 ms 512 KB correct
32 Correct 8 ms 512 KB correct
33 Correct 8 ms 512 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 17 ms 512 KB correct
15 Correct 18 ms 512 KB correct
16 Correct 18 ms 512 KB correct
17 Correct 18 ms 512 KB correct
18 Correct 6 ms 512 KB correct
19 Correct 15 ms 512 KB correct
20 Correct 14 ms 512 KB correct
21 Correct 13 ms 512 KB correct
22 Correct 8 ms 512 KB correct
23 Correct 7 ms 512 KB correct
24 Correct 6 ms 512 KB correct
25 Correct 1 ms 512 KB correct
26 Correct 6 ms 512 KB correct
27 Correct 7 ms 512 KB correct
28 Correct 3 ms 512 KB correct
29 Correct 1 ms 512 KB correct
30 Correct 8 ms 512 KB correct
31 Correct 8 ms 512 KB correct
32 Correct 8 ms 512 KB correct
33 Correct 8 ms 512 KB correct
34 Incorrect 1203 ms 2628 KB WA in grader: NO
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 826 ms 4232 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 17 ms 512 KB correct
15 Correct 18 ms 512 KB correct
16 Correct 18 ms 512 KB correct
17 Correct 18 ms 512 KB correct
18 Correct 6 ms 512 KB correct
19 Correct 15 ms 512 KB correct
20 Correct 14 ms 512 KB correct
21 Correct 13 ms 512 KB correct
22 Correct 8 ms 512 KB correct
23 Correct 7 ms 512 KB correct
24 Correct 6 ms 512 KB correct
25 Correct 1 ms 512 KB correct
26 Correct 6 ms 512 KB correct
27 Correct 7 ms 512 KB correct
28 Correct 3 ms 512 KB correct
29 Correct 1 ms 512 KB correct
30 Correct 8 ms 512 KB correct
31 Correct 8 ms 512 KB correct
32 Correct 8 ms 512 KB correct
33 Correct 8 ms 512 KB correct
34 Incorrect 1203 ms 2628 KB WA in grader: NO
35 Halted 0 ms 0 KB -