Submission #742727

# Submission time Handle Problem Language Result Execution time Memory
742727 2023-05-16T19:50:32 Z sidon Simurgh (IOI17_simurgh) C++17
100 / 100
384 ms 8260 KB
#include <bits/stdc++.h>
#include "simurgh.h"
#define pb push_back
using namespace std;

struct UFDS {
	vector<int> e;
	int operator()(int u) {
		return e[u] < 0 ? u : e[u] = (*this)(e[u]);
	}
	bool operator()(int u, int v) {
		if((u = (*this)(u)) == (v = (*this)(v))) return false;
		if(e[u] > e[v]) swap(u, v);
		e[u] += e[v], e[v] = u;
		return true;
	}
	UFDS(int n) { e.assign(n, -1); }
};

const int Z = 500, NE = Z * Z / 2;

int vis[Z], visE[NE], t[NE], over[NE];
vector<int> st;
vector<array<int, 2>> g[Z], s, h[NE], q;
vector<array<int, 3>> o;

int ask(int u, int v) {
	for(int &j : st) if(j == u) j = v;
	int res = count_common_roads(st);
	for(int &j : st) if(j == v) j = u;

	return res;
}

void dfs(int u, int p) {
	vis[u] = 1;
	for(auto [v, i] : g[u]) if(v != p) {
		if(vis[v] == 1) {
			for(int j = size(s); j--; ) {
				over[s[j][1]] = i;
				t[s[j][1]] = -1;
				if(s[j][0] == v) break;
				if(!visE[s[j][1]]++) o.pb({s[j][1], s[j-1][1], i});
			}
		} else if(!vis[v]) {
			s.pb({u, i});
			st.pb(i);
			t[i] = 1;
			dfs(v, u);
			s.pop_back();
		}
	}
	vis[u] = 2;
}

void color(int u) {
	for(auto [v, w] : h[u]) if(t[v] < 0) {
		t[v] = t[u] ^ w;
		color(v);
	}
}

vector<int> find_roads(int n, vector<int> U, vector<int> V) {
	for(int i = size(U); i--; ) {
		g[U[i]].pb({V[i], i});
		g[V[i]].pb({U[i], i});
	}

	fill(t, t + NE, -1);
	dfs(0, 0);

	int def = count_common_roads(st);

	for(auto [a, b, i] : o) {	
		int x = ask(a, i), y = ask(b, i);

		h[b].pb({a, x != y});
		h[a].pb({b, x != y});

		if(x != y) q.pb({a, x < y});
	}

	while(1) {
		for(auto [u, w] : q) if(t[u] < 0) {
			t[u] = w;
			color(u);
		}
		q.clear();

		bool done = 1;
		for(int i : st) if(t[i] < 0) {
			int e = over[i];
			done = 0;

			q.pb({i, ask(i, e) < def});
		} 
		if(done) break;
	}

	for(int u = 0; u < n; ++u) {
		vector<int> a;
		for(auto [v, i] : g[u]) if(u < v && t[i] < 0)
			a.pb(i);

		while(!empty(a)) {
			int x = 0;
			for(int y = 1<<10; y /= 2; ) if(x + y <= (int)size(a)) {
				x += y;

				UFDS uf(n);
				vector<int> qry;
				for(int i = 0; i < x; ++i) {
					uf(U[a[i]], V[a[i]]);
					qry.pb(a[i]);
				}

				int cnt {};
				for(int e : st) if(uf(U[e], V[e])) {
					qry.pb(e);
					cnt += t[e];
				}

				if(cnt < count_common_roads(qry)) x -= y;
			}
			for(int i = 0; i < x; ++i)
				t[a[i]] = 0;
			if(x == (int)size(a)) break;
			t[a[x]] = 1;
			a = vector<int> {begin(a) + x + 1, end(a)};			
		}
	}

	vector<int> res;
	for(int i = size(U); i--; )
		if(t[i] == 1) res.pb(i);
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3668 KB correct
2 Correct 2 ms 3668 KB correct
3 Correct 2 ms 3668 KB correct
4 Correct 2 ms 3668 KB correct
5 Correct 2 ms 3668 KB correct
6 Correct 2 ms 3668 KB correct
7 Correct 2 ms 3668 KB correct
8 Correct 2 ms 3668 KB correct
9 Correct 2 ms 3668 KB correct
10 Correct 2 ms 3668 KB correct
11 Correct 2 ms 3668 KB correct
12 Correct 2 ms 3668 KB correct
13 Correct 2 ms 3668 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3668 KB correct
2 Correct 2 ms 3668 KB correct
3 Correct 2 ms 3668 KB correct
4 Correct 2 ms 3668 KB correct
5 Correct 2 ms 3668 KB correct
6 Correct 2 ms 3668 KB correct
7 Correct 2 ms 3668 KB correct
8 Correct 2 ms 3668 KB correct
9 Correct 2 ms 3668 KB correct
10 Correct 2 ms 3668 KB correct
11 Correct 2 ms 3668 KB correct
12 Correct 2 ms 3668 KB correct
13 Correct 2 ms 3668 KB correct
14 Correct 3 ms 3796 KB correct
15 Correct 3 ms 3796 KB correct
16 Correct 3 ms 3796 KB correct
17 Correct 3 ms 3796 KB correct
18 Correct 3 ms 3668 KB correct
19 Correct 3 ms 3812 KB correct
20 Correct 3 ms 3796 KB correct
21 Correct 3 ms 3796 KB correct
22 Correct 3 ms 3796 KB correct
23 Correct 3 ms 3668 KB correct
24 Correct 3 ms 3668 KB correct
25 Correct 2 ms 3668 KB correct
26 Correct 3 ms 3796 KB correct
27 Correct 3 ms 3668 KB correct
28 Correct 3 ms 3668 KB correct
29 Correct 2 ms 3732 KB correct
30 Correct 3 ms 3680 KB correct
31 Correct 3 ms 3668 KB correct
32 Correct 3 ms 3668 KB correct
33 Correct 4 ms 3668 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3668 KB correct
2 Correct 2 ms 3668 KB correct
3 Correct 2 ms 3668 KB correct
4 Correct 2 ms 3668 KB correct
5 Correct 2 ms 3668 KB correct
6 Correct 2 ms 3668 KB correct
7 Correct 2 ms 3668 KB correct
8 Correct 2 ms 3668 KB correct
9 Correct 2 ms 3668 KB correct
10 Correct 2 ms 3668 KB correct
11 Correct 2 ms 3668 KB correct
12 Correct 2 ms 3668 KB correct
13 Correct 2 ms 3668 KB correct
14 Correct 3 ms 3796 KB correct
15 Correct 3 ms 3796 KB correct
16 Correct 3 ms 3796 KB correct
17 Correct 3 ms 3796 KB correct
18 Correct 3 ms 3668 KB correct
19 Correct 3 ms 3812 KB correct
20 Correct 3 ms 3796 KB correct
21 Correct 3 ms 3796 KB correct
22 Correct 3 ms 3796 KB correct
23 Correct 3 ms 3668 KB correct
24 Correct 3 ms 3668 KB correct
25 Correct 2 ms 3668 KB correct
26 Correct 3 ms 3796 KB correct
27 Correct 3 ms 3668 KB correct
28 Correct 3 ms 3668 KB correct
29 Correct 2 ms 3732 KB correct
30 Correct 3 ms 3680 KB correct
31 Correct 3 ms 3668 KB correct
32 Correct 3 ms 3668 KB correct
33 Correct 4 ms 3668 KB correct
34 Correct 63 ms 4868 KB correct
35 Correct 59 ms 4820 KB correct
36 Correct 47 ms 4692 KB correct
37 Correct 10 ms 3844 KB correct
38 Correct 61 ms 4852 KB correct
39 Correct 53 ms 4692 KB correct
40 Correct 47 ms 4692 KB correct
41 Correct 61 ms 4848 KB correct
42 Correct 58 ms 4860 KB correct
43 Correct 27 ms 4436 KB correct
44 Correct 21 ms 4308 KB correct
45 Correct 24 ms 4348 KB correct
46 Correct 19 ms 4256 KB correct
47 Correct 14 ms 3924 KB correct
48 Correct 4 ms 3796 KB correct
49 Correct 9 ms 3796 KB correct
50 Correct 13 ms 4052 KB correct
51 Correct 25 ms 4372 KB correct
52 Correct 21 ms 4248 KB correct
53 Correct 19 ms 4260 KB correct
54 Correct 27 ms 4436 KB correct
55 Correct 24 ms 4360 KB correct
56 Correct 26 ms 4308 KB correct
57 Correct 28 ms 4352 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3668 KB correct
2 Correct 3 ms 3664 KB correct
3 Correct 220 ms 6968 KB correct
4 Correct 384 ms 8084 KB correct
5 Correct 348 ms 8196 KB correct
6 Correct 304 ms 8204 KB correct
7 Correct 372 ms 8092 KB correct
8 Correct 383 ms 8140 KB correct
9 Correct 371 ms 8076 KB correct
10 Correct 384 ms 8204 KB correct
11 Correct 345 ms 8144 KB correct
12 Correct 381 ms 8160 KB correct
13 Correct 2 ms 3668 KB correct
14 Correct 374 ms 8260 KB correct
15 Correct 377 ms 8140 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3668 KB correct
2 Correct 2 ms 3668 KB correct
3 Correct 2 ms 3668 KB correct
4 Correct 2 ms 3668 KB correct
5 Correct 2 ms 3668 KB correct
6 Correct 2 ms 3668 KB correct
7 Correct 2 ms 3668 KB correct
8 Correct 2 ms 3668 KB correct
9 Correct 2 ms 3668 KB correct
10 Correct 2 ms 3668 KB correct
11 Correct 2 ms 3668 KB correct
12 Correct 2 ms 3668 KB correct
13 Correct 2 ms 3668 KB correct
14 Correct 3 ms 3796 KB correct
15 Correct 3 ms 3796 KB correct
16 Correct 3 ms 3796 KB correct
17 Correct 3 ms 3796 KB correct
18 Correct 3 ms 3668 KB correct
19 Correct 3 ms 3812 KB correct
20 Correct 3 ms 3796 KB correct
21 Correct 3 ms 3796 KB correct
22 Correct 3 ms 3796 KB correct
23 Correct 3 ms 3668 KB correct
24 Correct 3 ms 3668 KB correct
25 Correct 2 ms 3668 KB correct
26 Correct 3 ms 3796 KB correct
27 Correct 3 ms 3668 KB correct
28 Correct 3 ms 3668 KB correct
29 Correct 2 ms 3732 KB correct
30 Correct 3 ms 3680 KB correct
31 Correct 3 ms 3668 KB correct
32 Correct 3 ms 3668 KB correct
33 Correct 4 ms 3668 KB correct
34 Correct 63 ms 4868 KB correct
35 Correct 59 ms 4820 KB correct
36 Correct 47 ms 4692 KB correct
37 Correct 10 ms 3844 KB correct
38 Correct 61 ms 4852 KB correct
39 Correct 53 ms 4692 KB correct
40 Correct 47 ms 4692 KB correct
41 Correct 61 ms 4848 KB correct
42 Correct 58 ms 4860 KB correct
43 Correct 27 ms 4436 KB correct
44 Correct 21 ms 4308 KB correct
45 Correct 24 ms 4348 KB correct
46 Correct 19 ms 4256 KB correct
47 Correct 14 ms 3924 KB correct
48 Correct 4 ms 3796 KB correct
49 Correct 9 ms 3796 KB correct
50 Correct 13 ms 4052 KB correct
51 Correct 25 ms 4372 KB correct
52 Correct 21 ms 4248 KB correct
53 Correct 19 ms 4260 KB correct
54 Correct 27 ms 4436 KB correct
55 Correct 24 ms 4360 KB correct
56 Correct 26 ms 4308 KB correct
57 Correct 28 ms 4352 KB correct
58 Correct 2 ms 3668 KB correct
59 Correct 3 ms 3664 KB correct
60 Correct 220 ms 6968 KB correct
61 Correct 384 ms 8084 KB correct
62 Correct 348 ms 8196 KB correct
63 Correct 304 ms 8204 KB correct
64 Correct 372 ms 8092 KB correct
65 Correct 383 ms 8140 KB correct
66 Correct 371 ms 8076 KB correct
67 Correct 384 ms 8204 KB correct
68 Correct 345 ms 8144 KB correct
69 Correct 381 ms 8160 KB correct
70 Correct 2 ms 3668 KB correct
71 Correct 374 ms 8260 KB correct
72 Correct 377 ms 8140 KB correct
73 Correct 2 ms 3668 KB correct
74 Correct 378 ms 8072 KB correct
75 Correct 365 ms 8140 KB correct
76 Correct 140 ms 5560 KB correct
77 Correct 375 ms 8192 KB correct
78 Correct 354 ms 8184 KB correct
79 Correct 380 ms 8180 KB correct
80 Correct 373 ms 8220 KB correct
81 Correct 320 ms 7872 KB correct
82 Correct 333 ms 8116 KB correct
83 Correct 219 ms 6316 KB correct
84 Correct 167 ms 6868 KB correct
85 Correct 138 ms 6936 KB correct
86 Correct 98 ms 5676 KB correct
87 Correct 78 ms 5332 KB correct
88 Correct 65 ms 4872 KB correct
89 Correct 66 ms 4816 KB correct
90 Correct 59 ms 4772 KB correct
91 Correct 30 ms 3924 KB correct
92 Correct 13 ms 3816 KB correct
93 Correct 135 ms 6796 KB correct
94 Correct 92 ms 5572 KB correct
95 Correct 88 ms 5636 KB correct
96 Correct 57 ms 4820 KB correct
97 Correct 63 ms 4980 KB correct
98 Correct 71 ms 5412 KB correct
99 Correct 63 ms 4864 KB correct
100 Correct 38 ms 4052 KB correct
101 Correct 18 ms 3872 KB correct
102 Correct 127 ms 6096 KB correct
103 Correct 163 ms 6120 KB correct
104 Correct 169 ms 6056 KB correct
105 Correct 134 ms 6172 KB correct