Submission #960985

# Submission time Handle Problem Language Result Execution time Memory
960985 2024-04-11T10:35:00 Z Trisanu_Das Simurgh (IOI17_simurgh) C++17
100 / 100
189 ms 9992 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 1 ms 4696 KB correct
2 Correct 1 ms 4700 KB correct
3 Correct 2 ms 4696 KB correct
4 Correct 1 ms 4700 KB correct
5 Correct 1 ms 4700 KB correct
6 Correct 1 ms 4700 KB correct
7 Correct 1 ms 4700 KB correct
8 Correct 2 ms 4696 KB correct
9 Correct 1 ms 4700 KB correct
10 Correct 1 ms 4700 KB correct
11 Correct 1 ms 4700 KB correct
12 Correct 3 ms 4700 KB correct
13 Correct 1 ms 4700 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB correct
2 Correct 1 ms 4700 KB correct
3 Correct 2 ms 4696 KB correct
4 Correct 1 ms 4700 KB correct
5 Correct 1 ms 4700 KB correct
6 Correct 1 ms 4700 KB correct
7 Correct 1 ms 4700 KB correct
8 Correct 2 ms 4696 KB correct
9 Correct 1 ms 4700 KB correct
10 Correct 1 ms 4700 KB correct
11 Correct 1 ms 4700 KB correct
12 Correct 3 ms 4700 KB correct
13 Correct 1 ms 4700 KB correct
14 Correct 3 ms 4700 KB correct
15 Correct 2 ms 4700 KB correct
16 Correct 3 ms 4952 KB correct
17 Correct 2 ms 4772 KB correct
18 Correct 1 ms 4696 KB correct
19 Correct 2 ms 4696 KB correct
20 Correct 2 ms 4696 KB correct
21 Correct 3 ms 4696 KB correct
22 Correct 2 ms 4700 KB correct
23 Correct 2 ms 4700 KB correct
24 Correct 1 ms 4700 KB correct
25 Correct 1 ms 4700 KB correct
26 Correct 2 ms 4700 KB correct
27 Correct 2 ms 4696 KB correct
28 Correct 1 ms 4700 KB correct
29 Correct 1 ms 4700 KB correct
30 Correct 2 ms 4700 KB correct
31 Correct 1 ms 4712 KB correct
32 Correct 2 ms 4700 KB correct
33 Correct 2 ms 4700 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB correct
2 Correct 1 ms 4700 KB correct
3 Correct 2 ms 4696 KB correct
4 Correct 1 ms 4700 KB correct
5 Correct 1 ms 4700 KB correct
6 Correct 1 ms 4700 KB correct
7 Correct 1 ms 4700 KB correct
8 Correct 2 ms 4696 KB correct
9 Correct 1 ms 4700 KB correct
10 Correct 1 ms 4700 KB correct
11 Correct 1 ms 4700 KB correct
12 Correct 3 ms 4700 KB correct
13 Correct 1 ms 4700 KB correct
14 Correct 3 ms 4700 KB correct
15 Correct 2 ms 4700 KB correct
16 Correct 3 ms 4952 KB correct
17 Correct 2 ms 4772 KB correct
18 Correct 1 ms 4696 KB correct
19 Correct 2 ms 4696 KB correct
20 Correct 2 ms 4696 KB correct
21 Correct 3 ms 4696 KB correct
22 Correct 2 ms 4700 KB correct
23 Correct 2 ms 4700 KB correct
24 Correct 1 ms 4700 KB correct
25 Correct 1 ms 4700 KB correct
26 Correct 2 ms 4700 KB correct
27 Correct 2 ms 4696 KB correct
28 Correct 1 ms 4700 KB correct
29 Correct 1 ms 4700 KB correct
30 Correct 2 ms 4700 KB correct
31 Correct 1 ms 4712 KB correct
32 Correct 2 ms 4700 KB correct
33 Correct 2 ms 4700 KB correct
34 Correct 27 ms 5724 KB correct
35 Correct 27 ms 5724 KB correct
36 Correct 23 ms 5468 KB correct
37 Correct 7 ms 4696 KB correct
38 Correct 32 ms 5724 KB correct
39 Correct 24 ms 5676 KB correct
40 Correct 22 ms 5616 KB correct
41 Correct 30 ms 5756 KB correct
42 Correct 26 ms 5760 KB correct
43 Correct 16 ms 5348 KB correct
44 Correct 11 ms 4956 KB correct
45 Correct 13 ms 5252 KB correct
46 Correct 15 ms 5180 KB correct
47 Correct 11 ms 4952 KB correct
48 Correct 3 ms 4744 KB correct
49 Correct 6 ms 4804 KB correct
50 Correct 8 ms 4956 KB correct
51 Correct 13 ms 5264 KB correct
52 Correct 11 ms 4956 KB correct
53 Correct 10 ms 5164 KB correct
54 Correct 16 ms 5444 KB correct
55 Correct 15 ms 5212 KB correct
56 Correct 16 ms 5208 KB correct
57 Correct 13 ms 5212 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB correct
2 Correct 2 ms 4700 KB correct
3 Correct 91 ms 7844 KB correct
4 Correct 173 ms 9068 KB correct
5 Correct 167 ms 9028 KB correct
6 Correct 147 ms 9048 KB correct
7 Correct 152 ms 9024 KB correct
8 Correct 147 ms 9196 KB correct
9 Correct 150 ms 9068 KB correct
10 Correct 159 ms 9048 KB correct
11 Correct 158 ms 9304 KB correct
12 Correct 161 ms 9032 KB correct
13 Correct 1 ms 4696 KB correct
14 Correct 145 ms 8868 KB correct
15 Correct 151 ms 9080 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB correct
2 Correct 1 ms 4700 KB correct
3 Correct 2 ms 4696 KB correct
4 Correct 1 ms 4700 KB correct
5 Correct 1 ms 4700 KB correct
6 Correct 1 ms 4700 KB correct
7 Correct 1 ms 4700 KB correct
8 Correct 2 ms 4696 KB correct
9 Correct 1 ms 4700 KB correct
10 Correct 1 ms 4700 KB correct
11 Correct 1 ms 4700 KB correct
12 Correct 3 ms 4700 KB correct
13 Correct 1 ms 4700 KB correct
14 Correct 3 ms 4700 KB correct
15 Correct 2 ms 4700 KB correct
16 Correct 3 ms 4952 KB correct
17 Correct 2 ms 4772 KB correct
18 Correct 1 ms 4696 KB correct
19 Correct 2 ms 4696 KB correct
20 Correct 2 ms 4696 KB correct
21 Correct 3 ms 4696 KB correct
22 Correct 2 ms 4700 KB correct
23 Correct 2 ms 4700 KB correct
24 Correct 1 ms 4700 KB correct
25 Correct 1 ms 4700 KB correct
26 Correct 2 ms 4700 KB correct
27 Correct 2 ms 4696 KB correct
28 Correct 1 ms 4700 KB correct
29 Correct 1 ms 4700 KB correct
30 Correct 2 ms 4700 KB correct
31 Correct 1 ms 4712 KB correct
32 Correct 2 ms 4700 KB correct
33 Correct 2 ms 4700 KB correct
34 Correct 27 ms 5724 KB correct
35 Correct 27 ms 5724 KB correct
36 Correct 23 ms 5468 KB correct
37 Correct 7 ms 4696 KB correct
38 Correct 32 ms 5724 KB correct
39 Correct 24 ms 5676 KB correct
40 Correct 22 ms 5616 KB correct
41 Correct 30 ms 5756 KB correct
42 Correct 26 ms 5760 KB correct
43 Correct 16 ms 5348 KB correct
44 Correct 11 ms 4956 KB correct
45 Correct 13 ms 5252 KB correct
46 Correct 15 ms 5180 KB correct
47 Correct 11 ms 4952 KB correct
48 Correct 3 ms 4744 KB correct
49 Correct 6 ms 4804 KB correct
50 Correct 8 ms 4956 KB correct
51 Correct 13 ms 5264 KB correct
52 Correct 11 ms 4956 KB correct
53 Correct 10 ms 5164 KB correct
54 Correct 16 ms 5444 KB correct
55 Correct 15 ms 5212 KB correct
56 Correct 16 ms 5208 KB correct
57 Correct 13 ms 5212 KB correct
58 Correct 1 ms 4700 KB correct
59 Correct 2 ms 4700 KB correct
60 Correct 91 ms 7844 KB correct
61 Correct 173 ms 9068 KB correct
62 Correct 167 ms 9028 KB correct
63 Correct 147 ms 9048 KB correct
64 Correct 152 ms 9024 KB correct
65 Correct 147 ms 9196 KB correct
66 Correct 150 ms 9068 KB correct
67 Correct 159 ms 9048 KB correct
68 Correct 158 ms 9304 KB correct
69 Correct 161 ms 9032 KB correct
70 Correct 1 ms 4696 KB correct
71 Correct 145 ms 8868 KB correct
72 Correct 151 ms 9080 KB correct
73 Correct 1 ms 4720 KB correct
74 Correct 189 ms 9060 KB correct
75 Correct 165 ms 8992 KB correct
76 Correct 64 ms 6748 KB correct
77 Correct 152 ms 9948 KB correct
78 Correct 154 ms 9992 KB correct
79 Correct 165 ms 9988 KB correct
80 Correct 144 ms 9928 KB correct
81 Correct 149 ms 9476 KB correct
82 Correct 149 ms 9888 KB correct
83 Correct 97 ms 7680 KB correct
84 Correct 65 ms 8284 KB correct
85 Correct 57 ms 8024 KB correct
86 Correct 46 ms 6748 KB correct
87 Correct 40 ms 6492 KB correct
88 Correct 38 ms 5724 KB correct
89 Correct 39 ms 5876 KB correct
90 Correct 32 ms 5700 KB correct
91 Correct 21 ms 4696 KB correct
92 Correct 8 ms 4700 KB correct
93 Correct 56 ms 8080 KB correct
94 Correct 45 ms 6732 KB correct
95 Correct 51 ms 6996 KB correct
96 Correct 29 ms 5724 KB correct
97 Correct 32 ms 5720 KB correct
98 Correct 37 ms 6516 KB correct
99 Correct 32 ms 5724 KB correct
100 Correct 21 ms 4956 KB correct
101 Correct 10 ms 4952 KB correct
102 Correct 54 ms 7388 KB correct
103 Correct 61 ms 7260 KB correct
104 Correct 60 ms 7260 KB correct
105 Correct 55 ms 7260 KB correct