Submission #601131

# Submission time Handle Problem Language Result Execution time Memory
601131 2022-07-21T11:50:23 Z Lucpp Simurgh (IOI17_simurgh) C++17
30 / 100
3000 ms 10132 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;

int n, m;
vector<pair<int, int>> edges;
vector<vector<pair<int, int>>> g1;
vector<set<pair<int, int>>> g;
vector<int> good;

void calc(int i){
	int start = edges[i].first, goal = edges[i].second;
	queue<int> q;
	q.push(start);
	vector<bool> vis(n);
	vis[start] = true;
	vector<pair<int, int>> last(n);
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(auto [v, ind] : g[u]){
			if(ind == i) continue;
			if(!vis[v]){
				vis[v] = true;
				q.push(v);
				last[v] = {u, ind};
			}
		}
	}
	if(!vis[goal]){ // bridge
		good[i] = true;
		return;
	}
	vector<int> cycle;
	vector<int> inCycle(m);
	int u = goal;
	while(u != start){
		inCycle[last[u].second] = true;
		cycle.push_back(last[u].second);
		u = last[u].first;
	}
	inCycle[i] = true;
	cycle.push_back(i);
	vector<int> forest;
	for(u = 0; u < n; u++){
		if(u != start){
			int e = last[u].second;
			if(!inCycle[e]) forest.push_back(e);
		}
	}
	int c = (int)cycle.size();
	vector<int> ans(c);
	for(int j = 0; j < c; j++){
		if(good[cycle[j]] == 1) ans[j] = -1;
		else{
			vector<int> v;
			for(int k = 0; k < c; k++){
				if(k != j) v.push_back(cycle[k]);
			}
			for(int e : forest) v.push_back(e);
			ans[j] = count_common_roads(v);
		}
	}
	for(int j = 0; j < c; j++){
		int ma = 0;
		for(int k = 0; k < c; k++){
			if(j != k) ma = max(ma, ans[k]);
		}
		good[cycle[j]] = ma > ans[j];
		if(good[cycle[j]] == 0){
			int a = edges[cycle[j]].first, b = edges[cycle[j]].second;
			g[a].erase({b, cycle[j]});
			g[b].erase({a, cycle[j]});
		}
	}
}

mt19937 mt(1243234);

vector<bool> vis;
vector<int> path;
void dfs(int u){
	vis[u] = true;
	shuffle(g1[u].begin(), g1[u].end(), mt);
	for(auto [v, ind] : g1[u]){
		if(vis[v] || good[ind] == 0) continue;
		dfs(v);
		path.push_back(ind);
	}
}

vector<int> find_roads(int n_, vector<int> u, vector<int> v) {
	n = n_;
	m = (int)u.size();
	g1.resize(n);
	for(int i = 0; i < m; i++){
		edges.emplace_back(u[i], v[i]);
		g1[u[i]].emplace_back(v[i], i);
		g1[v[i]].emplace_back(u[i], i);
	}
	good.resize(m, -1);
	for(int it = 0; it < 500; it++){
		path.clear();
		vis.assign(n, false);
		dfs(0);
		if((int)path.size() != n-1) break;
		if(count_common_roads(path) == 0){
			for(int e : path) good[e] = 0;
		}
	}
	g.resize(n);
	for(int a = 0; a < n; a++){
		for(auto [b, ind] : g1[a]){
			if(good[ind] != 0) g[a].emplace(b, ind);
		}
	}
	for(int i = 0; i < m; i++){
		if(good[i] == -1){
			calc(i);
		}
	}
	vector<int> r;
	for(int i = 0; i < m; i++) if(good[i] == 1) r.push_back(i);
	return r;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 24 ms 340 KB correct
15 Correct 36 ms 500 KB correct
16 Correct 29 ms 376 KB correct
17 Correct 23 ms 372 KB correct
18 Correct 10 ms 328 KB correct
19 Correct 22 ms 372 KB correct
20 Correct 22 ms 368 KB correct
21 Correct 19 ms 372 KB correct
22 Correct 17 ms 356 KB correct
23 Correct 14 ms 340 KB correct
24 Correct 14 ms 348 KB correct
25 Correct 3 ms 212 KB correct
26 Correct 14 ms 348 KB correct
27 Correct 14 ms 344 KB correct
28 Correct 7 ms 340 KB correct
29 Correct 4 ms 212 KB correct
30 Correct 15 ms 352 KB correct
31 Correct 18 ms 340 KB correct
32 Correct 15 ms 356 KB correct
33 Correct 15 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 24 ms 340 KB correct
15 Correct 36 ms 500 KB correct
16 Correct 29 ms 376 KB correct
17 Correct 23 ms 372 KB correct
18 Correct 10 ms 328 KB correct
19 Correct 22 ms 372 KB correct
20 Correct 22 ms 368 KB correct
21 Correct 19 ms 372 KB correct
22 Correct 17 ms 356 KB correct
23 Correct 14 ms 340 KB correct
24 Correct 14 ms 348 KB correct
25 Correct 3 ms 212 KB correct
26 Correct 14 ms 348 KB correct
27 Correct 14 ms 344 KB correct
28 Correct 7 ms 340 KB correct
29 Correct 4 ms 212 KB correct
30 Correct 15 ms 352 KB correct
31 Correct 18 ms 340 KB correct
32 Correct 15 ms 356 KB correct
33 Correct 15 ms 348 KB correct
34 Correct 2142 ms 3488 KB correct
35 Correct 1873 ms 3328 KB correct
36 Correct 1337 ms 2760 KB correct
37 Correct 41 ms 504 KB correct
38 Correct 2274 ms 3480 KB correct
39 Correct 1902 ms 3228 KB correct
40 Correct 1382 ms 2828 KB correct
41 Execution timed out 3047 ms 4372 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 2 ms 212 KB correct
3 Execution timed out 3044 ms 10132 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 24 ms 340 KB correct
15 Correct 36 ms 500 KB correct
16 Correct 29 ms 376 KB correct
17 Correct 23 ms 372 KB correct
18 Correct 10 ms 328 KB correct
19 Correct 22 ms 372 KB correct
20 Correct 22 ms 368 KB correct
21 Correct 19 ms 372 KB correct
22 Correct 17 ms 356 KB correct
23 Correct 14 ms 340 KB correct
24 Correct 14 ms 348 KB correct
25 Correct 3 ms 212 KB correct
26 Correct 14 ms 348 KB correct
27 Correct 14 ms 344 KB correct
28 Correct 7 ms 340 KB correct
29 Correct 4 ms 212 KB correct
30 Correct 15 ms 352 KB correct
31 Correct 18 ms 340 KB correct
32 Correct 15 ms 356 KB correct
33 Correct 15 ms 348 KB correct
34 Correct 2142 ms 3488 KB correct
35 Correct 1873 ms 3328 KB correct
36 Correct 1337 ms 2760 KB correct
37 Correct 41 ms 504 KB correct
38 Correct 2274 ms 3480 KB correct
39 Correct 1902 ms 3228 KB correct
40 Correct 1382 ms 2828 KB correct
41 Execution timed out 3047 ms 4372 KB Time limit exceeded
42 Halted 0 ms 0 KB -