Submission #1075998

# Submission time Handle Problem Language Result Execution time Memory
1075998 2024-08-26T10:20:55 Z NeroZein Simurgh (IOI17_simurgh) C++17
30 / 100
1937 ms 2844 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> find_roads(int n, vector<int> eu, vector<int> ev) {
	
	int cc;
	vector<int> p(n), sz(n);
	
	function<int(int)> get = [&](int v) {
		return p[v] = (p[v] == v ? v : get(p[v]));
	};
	
	auto unite = [&](int u, int v) {
		u = get(u); v = get(v);
		if (u == v) {
			return false;
		}
		if (sz[u] > sz[v]) {
			swap(u, v);
		}
		--cc;
		p[u] = v;
		sz[v] += sz[u];
		return true;
	};
	
	auto init_dsu = [&]() {
		cc = n;
		iota(p.begin(), p.end(), 0);
		fill(sz.begin(), sz.end(), 1);
	};
	
	auto simulate = [&](vector<int> edges) {
		assert((int) edges.size() == n - 1); 
		init_dsu();
		for (int i = 0; i < n - 1; ++i) {
			unite(eu[edges[i]], ev[edges[i]]);
		}
	};
	
	int m = (int) eu.size();
	init_dsu();
	vector<int> in_tree, out_tree;
	for (int i = 0; i < m; ++i) {
		if (unite(eu[i], ev[i])) {
			in_tree.push_back(i);
		} else {
			out_tree.push_back(i);
		}
	}
	
	int x = count_common_roads(in_tree);
	vector<int> state(m, -1);
	for (int i : out_tree) {
		//~ cout << "tree: ";
		//~ for (int j : in_tree) {
			//~ cout << j << ' ';
		//~ }
		//~ cout << endl; 
		vector<int> unknown;
		state[i] = 0;
		assert((int) in_tree.size() == n - 1); 
		for (int j = 0; j < n - 1; ++j) {
			int label = in_tree[j];
			vector<int> tmp = in_tree;
			tmp.erase(tmp.begin() + j);
			tmp.push_back(i);
			simulate(tmp); 
			if (cc != 1) {
				//~ cout << "i " << i << endl;
				//~ cout << "TMP: ";
				//~ for (int k : tmp) {
					//~ cout << k << ' ';
				//~ }
				//~ cout << endl; 
				continue; 
			}
			int y = count_common_roads(tmp);
			if (state[label] == -1) {
				if (y > x) {
					state[label] = 0;
					state[i] = 1;
					in_tree = tmp;
					x = y;
					break;
				} else if (y == x) {
					unknown.push_back(label);
				} else {//y < x
					state[label] = 1;
					state[i] = 0;//doesn't matter
					break; 
				}
			} else {
				if (state[label] == 1) {
					continue;
				}
				assert(state[label] == 0);
				//state[label] = 0
				if (y > x) {
					x = y; 
					state[i] = 1;
					in_tree = tmp;
				} else {
					//~ cout << "i, label, y, x: " << i << ' ' << label << ' ' << y << ' ' << x << endl;
					//~ cout << "wut: " << i << endl; 
					assert(y == x);
					state[i] = 0;//doesn't matter
				}
				break;
			}
		}
		//~ cout << "I: " << i << ' ' << state[i] << endl;
		//~ cout << "same: ";
		//~ for (int label : unknown) {
			//~ cout << "label: " << label << ' ';
			//~ state[label] = state[i]; 
		//~ }
		//~ cout << endl;
		//~ cout << "STATE: ";
		//~ for (int j = 0; j < m; ++j) {
			//~ cout << state[j] << ' ';
		//~ }
		//~ cout << endl; 
		//~ cout << "i, state[i]: " << i << ' ' << state[i] << endl; 
	}
	return in_tree;
}
//~ int common = count_common_roads(r);
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 344 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 344 KB correct
14 Correct 55 ms 348 KB correct
15 Correct 48 ms 348 KB correct
16 Correct 47 ms 348 KB correct
17 Correct 44 ms 436 KB correct
18 Correct 14 ms 360 KB correct
19 Correct 46 ms 348 KB correct
20 Correct 39 ms 440 KB correct
21 Correct 38 ms 344 KB correct
22 Correct 31 ms 464 KB correct
23 Correct 26 ms 344 KB correct
24 Correct 25 ms 348 KB correct
25 Correct 1 ms 436 KB correct
26 Correct 26 ms 348 KB correct
27 Correct 27 ms 460 KB correct
28 Correct 9 ms 344 KB correct
29 Correct 3 ms 348 KB correct
30 Correct 27 ms 348 KB correct
31 Correct 27 ms 348 KB correct
32 Correct 27 ms 452 KB correct
33 Correct 26 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 344 KB correct
14 Correct 55 ms 348 KB correct
15 Correct 48 ms 348 KB correct
16 Correct 47 ms 348 KB correct
17 Correct 44 ms 436 KB correct
18 Correct 14 ms 360 KB correct
19 Correct 46 ms 348 KB correct
20 Correct 39 ms 440 KB correct
21 Correct 38 ms 344 KB correct
22 Correct 31 ms 464 KB correct
23 Correct 26 ms 344 KB correct
24 Correct 25 ms 348 KB correct
25 Correct 1 ms 436 KB correct
26 Correct 26 ms 348 KB correct
27 Correct 27 ms 460 KB correct
28 Correct 9 ms 344 KB correct
29 Correct 3 ms 348 KB correct
30 Correct 27 ms 348 KB correct
31 Correct 27 ms 348 KB correct
32 Correct 27 ms 452 KB correct
33 Correct 26 ms 348 KB correct
34 Incorrect 1925 ms 1320 KB WA in grader: NO
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB correct
2 Correct 1 ms 348 KB correct
3 Incorrect 1937 ms 2844 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 1 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 0 ms 344 KB correct
14 Correct 55 ms 348 KB correct
15 Correct 48 ms 348 KB correct
16 Correct 47 ms 348 KB correct
17 Correct 44 ms 436 KB correct
18 Correct 14 ms 360 KB correct
19 Correct 46 ms 348 KB correct
20 Correct 39 ms 440 KB correct
21 Correct 38 ms 344 KB correct
22 Correct 31 ms 464 KB correct
23 Correct 26 ms 344 KB correct
24 Correct 25 ms 348 KB correct
25 Correct 1 ms 436 KB correct
26 Correct 26 ms 348 KB correct
27 Correct 27 ms 460 KB correct
28 Correct 9 ms 344 KB correct
29 Correct 3 ms 348 KB correct
30 Correct 27 ms 348 KB correct
31 Correct 27 ms 348 KB correct
32 Correct 27 ms 452 KB correct
33 Correct 26 ms 348 KB correct
34 Incorrect 1925 ms 1320 KB WA in grader: NO
35 Halted 0 ms 0 KB -