답안 #137723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137723 2019-07-28T09:09:10 Z Mahdi_Jfri Simurgh (IOI17_simurgh) C++14
100 / 100
386 ms 8176 KB
#include "simurgh.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

const int maxn = 5e2 + 20;
const int maxm = maxn * maxn + 20;

int from[maxm] , to[maxm] , par[maxn] , h[maxn] , is[maxm] , ed[maxm] , num;

vector<int> adj[maxn] , bc[maxn] , ind;

bool visited[maxn] , tree[maxm];

void plant(int v)
{
	visited[v] = 1;
	for(auto e : adj[v])
	{
		int u = from[e] ^ to[e] ^ v;
		if(!visited[u])
		{
			ind.pb(e);
			h[u] = h[v] + 1;
			par[u] = e;
			tree[e] = 1;
			plant(u);
		}
		else if(h[u] < h[v] - 1)
			bc[v].pb(e);
	}
}

vector<int> rem(vector<int> x , int y)
{
	vector<int> nw;
	for(auto k : x)
		if(k != y)
			nw.pb(k);

	return nw;
}

bool cmp(int x , int y)
{
	x = min(h[from[x]] , h[to[x]]);
	y = min(h[from[y]] , h[to[y]]);

	return x > y;
}

int wtf[maxm];

int get(vector<int> &bc , int sz)
{
	if(!sz)
		return 0;

	vector<int> shit;
	for(int i = 0; i < sz; i++)
	{
		int e = bc[i];
		tree[wtf[e]] = 0;
		shit.pb(e);
	}

	int ts = 0;
	for(auto x : ind)
		if(tree[x])
		{
			if(is[x] == 1)
				ts++;
			shit.pb(x);
		}

	for(int i = 0; i < sz; i++)
	{
		int e = bc[i];
		tree[wtf[e]] = 1;
	}

	return count_common_roads(shit) - ts;
}

void dfs(int v)
{
	for(auto e : adj[v])
	{
		int u = from[e] ^ to[e] ^ v;
		if(h[u] == h[v] + 1)
			dfs(u);
	}

	if(bc[v].empty())
		return;

	int last = v;

	sort(bc[v].begin() , bc[v].end() , cmp);
	for(auto e : bc[v])
	{
		while(!last);
		wtf[e] = par[last];
		last = from[e] ^ to[e] ^ v;
	}

	int k = bc[v].size() , st = 0 , stl = 0 , shit = get(bc[v] , k);
	while(k && shit > st)
	{
		int l = stl , r = k;
		while(r - l > 1)
		{
			int m = (l + r) / 2;
			if(get(bc[v] , m) > st)
				r = m;
			else
				l = m;
		}

		is[bc[v][r - 1]] = 1;
		stl = r;
		st++;
	}

}

vector<int> find_roads(int n,vector<int> A,vector<int> B)
{
	n = n;
	int m = A.size();
	for(int i = 0; i < m; i++)
	{
		int a = A[i] , b = B[i];

		adj[a].pb(i);
		adj[b].pb(i);

		from[i] = a , to[i] = b;
	}

	plant(0);

	memset(ed , -1 , sizeof ed);

	num = count_common_roads(ind);
	for(int i = 0; i < m; i++)
		if(!tree[i])
		{
			int v = from[i] , u = to[i];
			if(h[v] < h[u])
				swap(v , u);

			vector<int> ed;

			bool has0 = 0;
			while(v != u)
			{
				if(is[par[v]] == 0)
					has0 = 1;

				ed.pb(par[v]);
				v = from[par[v]] ^ to[par[v]] ^ v;
			}

			if(!has0)
				continue;

			vector<int> eq;
			for(auto e : ed)
			{
				if(is[e] != 0 && is[i] != 0)
					continue;

				ind = rem(ind , e);
				ind.pb(i);
				int nw = count_common_roads(ind);
				ind.pop_back() , ind.pb(e);

				if(nw == num)
				{
					if(is[e] != 0)
						is[i] = is[e];
					else
						eq.pb(e);
				}
				else if(nw == num + 1)
				{
					is[i] = 1;
					is[e] = -1;
				}
				else
				{
					is[e] = 1;
					is[i] = -1;
				}
			}

			if((int)eq.size() == (int)ed.size())
				is[i] = -1;

			for(auto e : eq)
				is[e] = is[i];
		}

	for(auto x : ind)
		if(is[x] == 0)
			is[x] = 1;

	dfs(0);

	vector<int> ans;
	for(int i = 0; i < m; i++)
	{
		if(!is[i])
			is[i] = -1;
		if(is[i] == 1)
			ans.pb(i);
	}

	while(count_common_roads(ans) != n - 1);

	return ans;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1400 KB correct
2 Correct 3 ms 1400 KB correct
3 Correct 3 ms 1400 KB correct
4 Correct 3 ms 1400 KB correct
5 Correct 3 ms 1400 KB correct
6 Correct 3 ms 1400 KB correct
7 Correct 3 ms 1372 KB correct
8 Correct 3 ms 1400 KB correct
9 Correct 3 ms 1400 KB correct
10 Correct 3 ms 1400 KB correct
11 Correct 3 ms 1400 KB correct
12 Correct 3 ms 1400 KB correct
13 Correct 3 ms 1400 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1400 KB correct
2 Correct 3 ms 1400 KB correct
3 Correct 3 ms 1400 KB correct
4 Correct 3 ms 1400 KB correct
5 Correct 3 ms 1400 KB correct
6 Correct 3 ms 1400 KB correct
7 Correct 3 ms 1372 KB correct
8 Correct 3 ms 1400 KB correct
9 Correct 3 ms 1400 KB correct
10 Correct 3 ms 1400 KB correct
11 Correct 3 ms 1400 KB correct
12 Correct 3 ms 1400 KB correct
13 Correct 3 ms 1400 KB correct
14 Correct 4 ms 1528 KB correct
15 Correct 4 ms 1528 KB correct
16 Correct 4 ms 1528 KB correct
17 Correct 4 ms 1528 KB correct
18 Correct 4 ms 1400 KB correct
19 Correct 4 ms 1528 KB correct
20 Correct 4 ms 1528 KB correct
21 Correct 4 ms 1528 KB correct
22 Correct 4 ms 1528 KB correct
23 Correct 4 ms 1400 KB correct
24 Correct 4 ms 1528 KB correct
25 Correct 3 ms 1420 KB correct
26 Correct 4 ms 1400 KB correct
27 Correct 3 ms 1400 KB correct
28 Correct 3 ms 1400 KB correct
29 Correct 3 ms 1400 KB correct
30 Correct 4 ms 1528 KB correct
31 Correct 4 ms 1404 KB correct
32 Correct 4 ms 1400 KB correct
33 Correct 4 ms 1528 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1400 KB correct
2 Correct 3 ms 1400 KB correct
3 Correct 3 ms 1400 KB correct
4 Correct 3 ms 1400 KB correct
5 Correct 3 ms 1400 KB correct
6 Correct 3 ms 1400 KB correct
7 Correct 3 ms 1372 KB correct
8 Correct 3 ms 1400 KB correct
9 Correct 3 ms 1400 KB correct
10 Correct 3 ms 1400 KB correct
11 Correct 3 ms 1400 KB correct
12 Correct 3 ms 1400 KB correct
13 Correct 3 ms 1400 KB correct
14 Correct 4 ms 1528 KB correct
15 Correct 4 ms 1528 KB correct
16 Correct 4 ms 1528 KB correct
17 Correct 4 ms 1528 KB correct
18 Correct 4 ms 1400 KB correct
19 Correct 4 ms 1528 KB correct
20 Correct 4 ms 1528 KB correct
21 Correct 4 ms 1528 KB correct
22 Correct 4 ms 1528 KB correct
23 Correct 4 ms 1400 KB correct
24 Correct 4 ms 1528 KB correct
25 Correct 3 ms 1420 KB correct
26 Correct 4 ms 1400 KB correct
27 Correct 3 ms 1400 KB correct
28 Correct 3 ms 1400 KB correct
29 Correct 3 ms 1400 KB correct
30 Correct 4 ms 1528 KB correct
31 Correct 4 ms 1404 KB correct
32 Correct 4 ms 1400 KB correct
33 Correct 4 ms 1528 KB correct
34 Correct 60 ms 2956 KB correct
35 Correct 58 ms 2936 KB correct
36 Correct 45 ms 2552 KB correct
37 Correct 10 ms 1528 KB correct
38 Correct 59 ms 2936 KB correct
39 Correct 52 ms 2840 KB correct
40 Correct 44 ms 2552 KB correct
41 Correct 59 ms 2940 KB correct
42 Correct 58 ms 2936 KB correct
43 Correct 26 ms 2296 KB correct
44 Correct 22 ms 2040 KB correct
45 Correct 24 ms 2140 KB correct
46 Correct 21 ms 2040 KB correct
47 Correct 13 ms 1784 KB correct
48 Correct 6 ms 1528 KB correct
49 Correct 8 ms 1528 KB correct
50 Correct 13 ms 1656 KB correct
51 Correct 25 ms 2296 KB correct
52 Correct 22 ms 2044 KB correct
53 Correct 21 ms 2040 KB correct
54 Correct 26 ms 2296 KB correct
55 Correct 29 ms 2268 KB correct
56 Correct 30 ms 2296 KB correct
57 Correct 29 ms 2168 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1400 KB correct
2 Correct 3 ms 1400 KB correct
3 Correct 214 ms 5864 KB correct
4 Correct 376 ms 8056 KB correct
5 Correct 376 ms 8056 KB correct
6 Correct 374 ms 8176 KB correct
7 Correct 368 ms 8056 KB correct
8 Correct 360 ms 8112 KB correct
9 Correct 369 ms 8144 KB correct
10 Correct 372 ms 8056 KB correct
11 Correct 365 ms 8120 KB correct
12 Correct 370 ms 8048 KB correct
13 Correct 3 ms 1400 KB correct
14 Correct 370 ms 8100 KB correct
15 Correct 375 ms 8056 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1400 KB correct
2 Correct 3 ms 1400 KB correct
3 Correct 3 ms 1400 KB correct
4 Correct 3 ms 1400 KB correct
5 Correct 3 ms 1400 KB correct
6 Correct 3 ms 1400 KB correct
7 Correct 3 ms 1372 KB correct
8 Correct 3 ms 1400 KB correct
9 Correct 3 ms 1400 KB correct
10 Correct 3 ms 1400 KB correct
11 Correct 3 ms 1400 KB correct
12 Correct 3 ms 1400 KB correct
13 Correct 3 ms 1400 KB correct
14 Correct 4 ms 1528 KB correct
15 Correct 4 ms 1528 KB correct
16 Correct 4 ms 1528 KB correct
17 Correct 4 ms 1528 KB correct
18 Correct 4 ms 1400 KB correct
19 Correct 4 ms 1528 KB correct
20 Correct 4 ms 1528 KB correct
21 Correct 4 ms 1528 KB correct
22 Correct 4 ms 1528 KB correct
23 Correct 4 ms 1400 KB correct
24 Correct 4 ms 1528 KB correct
25 Correct 3 ms 1420 KB correct
26 Correct 4 ms 1400 KB correct
27 Correct 3 ms 1400 KB correct
28 Correct 3 ms 1400 KB correct
29 Correct 3 ms 1400 KB correct
30 Correct 4 ms 1528 KB correct
31 Correct 4 ms 1404 KB correct
32 Correct 4 ms 1400 KB correct
33 Correct 4 ms 1528 KB correct
34 Correct 60 ms 2956 KB correct
35 Correct 58 ms 2936 KB correct
36 Correct 45 ms 2552 KB correct
37 Correct 10 ms 1528 KB correct
38 Correct 59 ms 2936 KB correct
39 Correct 52 ms 2840 KB correct
40 Correct 44 ms 2552 KB correct
41 Correct 59 ms 2940 KB correct
42 Correct 58 ms 2936 KB correct
43 Correct 26 ms 2296 KB correct
44 Correct 22 ms 2040 KB correct
45 Correct 24 ms 2140 KB correct
46 Correct 21 ms 2040 KB correct
47 Correct 13 ms 1784 KB correct
48 Correct 6 ms 1528 KB correct
49 Correct 8 ms 1528 KB correct
50 Correct 13 ms 1656 KB correct
51 Correct 25 ms 2296 KB correct
52 Correct 22 ms 2044 KB correct
53 Correct 21 ms 2040 KB correct
54 Correct 26 ms 2296 KB correct
55 Correct 29 ms 2268 KB correct
56 Correct 30 ms 2296 KB correct
57 Correct 29 ms 2168 KB correct
58 Correct 3 ms 1400 KB correct
59 Correct 3 ms 1400 KB correct
60 Correct 214 ms 5864 KB correct
61 Correct 376 ms 8056 KB correct
62 Correct 376 ms 8056 KB correct
63 Correct 374 ms 8176 KB correct
64 Correct 368 ms 8056 KB correct
65 Correct 360 ms 8112 KB correct
66 Correct 369 ms 8144 KB correct
67 Correct 372 ms 8056 KB correct
68 Correct 365 ms 8120 KB correct
69 Correct 370 ms 8048 KB correct
70 Correct 3 ms 1400 KB correct
71 Correct 370 ms 8100 KB correct
72 Correct 375 ms 8056 KB correct
73 Correct 3 ms 1528 KB correct
74 Correct 371 ms 8144 KB correct
75 Correct 360 ms 7896 KB correct
76 Correct 134 ms 3908 KB correct
77 Correct 386 ms 8056 KB correct
78 Correct 375 ms 8156 KB correct
79 Correct 373 ms 8100 KB correct
80 Correct 361 ms 8008 KB correct
81 Correct 322 ms 7160 KB correct
82 Correct 360 ms 7928 KB correct
83 Correct 213 ms 4984 KB correct
84 Correct 175 ms 5584 KB correct
85 Correct 147 ms 5236 KB correct
86 Correct 94 ms 3960 KB correct
87 Correct 70 ms 3320 KB correct
88 Correct 58 ms 2936 KB correct
89 Correct 60 ms 2936 KB correct
90 Correct 51 ms 2552 KB correct
91 Correct 21 ms 1656 KB correct
92 Correct 14 ms 1556 KB correct
93 Correct 142 ms 5252 KB correct
94 Correct 94 ms 3960 KB correct
95 Correct 91 ms 4004 KB correct
96 Correct 52 ms 2680 KB correct
97 Correct 71 ms 2808 KB correct
98 Correct 67 ms 3320 KB correct
99 Correct 58 ms 2928 KB correct
100 Correct 30 ms 1912 KB correct
101 Correct 14 ms 1528 KB correct
102 Correct 171 ms 4804 KB correct
103 Correct 173 ms 4856 KB correct
104 Correct 167 ms 4844 KB correct
105 Correct 168 ms 4776 KB correct