Submission #423867

# Submission time Handle Problem Language Result Execution time Memory
423867 2021-06-11T13:29:32 Z AugustinasJucas Simurgh (IOI17_simurgh) C++14
51 / 100
455 ms 5268 KB
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
int N;
const int dydis = 501;
vector<pair<int, int> > brn;
vector<int> zn(dydis * dydis, -1);
vector<pair<int, int> > gr[dydis];
vector<int> tikrai;
int tevas[dydis];
int fP(int v){
	if(tevas[v] == v) return v;
	return tevas[v] = fP(tevas[v]);
}
void conn(int a, int b){
	a = fP(a);
	b = fP(b);
	if(a == b) return;
	tevas[a] = b;
}
set<int> virs;
bool vis[dydis] = {0};
int deg[dydis] = {0};
void form(){
	for(int i = 0; i < N; i++) {
		gr[i].clear();
		vis[i] = 0;
		deg[i] = 0;
	}
	virs.clear();
//	cout << "grafas:\n";
	for(int i = 0; i < (int) brn.size(); i++){
		if(zn[i] != -1) continue;
		int a = fP(brn[i].first);
		int b = fP(brn[i].second);
		if(a == b) continue;
		gr[a].push_back({b, i});
		gr[b].push_back({a, i});
//		cout << a << " -- " << b << endl;
		virs.insert(a); virs.insert(b);
	}
	//cout << endl;
}
vector<int> pl;
void dfs(int v){
	vis[v] = 1;
	for(auto x : gr[v]){
		if(vis[x.first]) continue;
		pl.push_back(x.second);
		deg[v]++;
		deg[x.first]++;
		dfs(x.first);
	}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	//count_common_roads
	N = n;
	vector<int> ret;
	for(int i = 0; i < N; i++) tevas[i] = i;
	for(int i = 0; i < (int)u.size(); i++) {
		brn.push_back({u[i], v[i]});
	}
	int it = 0;
	while((int) tikrai.size() != n-1){
		pl.clear();
		form();
		int v = *virs.begin();
		dfs(v);
		int u = -1;
		for(int i = 0; i < n; i++) if(deg[i] == 1) u = i;
	//	cout << "komponentai: \n"; for(int i = 0; i < n; i++) cout << i << ": " << fP(i) << endl; cout << endl;
	//	cout << "suformuoju medi: \n"; for(int i = 0; i < pl.size(); i++) cout << brn[pl[i]].first << " - > " << brn[pl[i]].second << endl;
	//	cout << "\nmedzio lapas: " << u << endl;
	//	cout << endl;
		vector<int> rest;
		for(int i = 0; i < (int)pl.size(); i++){
			int a = fP(brn[pl[i]].first);
			int b = fP(brn[pl[i]].second);
			if(a == u || b == u){
				continue;
			}
			rest.push_back(pl[i]);
		}
		for(auto x : tikrai) rest.push_back(x);
		vector<pair<int, int> > aa;
		int mx = 0;
		for(auto x : gr[u]){ 
			rest.push_back(x.second);
			int cm = count_common_roads(rest);
			aa.push_back({cm, x.second});
			mx = max(mx, cm);
			rest.pop_back();
		}
		for(auto x : aa){
			if(x.first == mx) {
				tikrai.push_back(x.second);
				zn[x.second] = 1;
				conn(brn[x.second].first, brn[x.second].second);
		//		cout << brn[x.second].first << " -> " << brn[x.second].second << " tikrai geras" << endl;
			}else{
				zn[x.second] = 0;
		//		cout << brn[x.second].first << " -> " << brn[x.second].second << " tikrai blogas" << endl;
			}
		}
	}

	return tikrai;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:63:6: warning: unused variable 'it' [-Wunused-variable]
   63 |  int it = 0;
      |      ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB correct
2 Correct 1 ms 1228 KB correct
3 Correct 1 ms 1228 KB correct
4 Correct 1 ms 1228 KB correct
5 Correct 1 ms 1228 KB correct
6 Correct 1 ms 1228 KB correct
7 Correct 1 ms 1228 KB correct
8 Correct 1 ms 1228 KB correct
9 Correct 1 ms 1228 KB correct
10 Correct 1 ms 1228 KB correct
11 Correct 1 ms 1228 KB correct
12 Correct 1 ms 1228 KB correct
13 Correct 1 ms 1228 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB correct
2 Correct 1 ms 1228 KB correct
3 Correct 1 ms 1228 KB correct
4 Correct 1 ms 1228 KB correct
5 Correct 1 ms 1228 KB correct
6 Correct 1 ms 1228 KB correct
7 Correct 1 ms 1228 KB correct
8 Correct 1 ms 1228 KB correct
9 Correct 1 ms 1228 KB correct
10 Correct 1 ms 1228 KB correct
11 Correct 1 ms 1228 KB correct
12 Correct 1 ms 1228 KB correct
13 Correct 1 ms 1228 KB correct
14 Correct 4 ms 1356 KB correct
15 Correct 4 ms 1356 KB correct
16 Correct 4 ms 1356 KB correct
17 Correct 3 ms 1356 KB correct
18 Correct 2 ms 1228 KB correct
19 Correct 4 ms 1356 KB correct
20 Correct 4 ms 1356 KB correct
21 Correct 3 ms 1356 KB correct
22 Correct 3 ms 1228 KB correct
23 Correct 3 ms 1228 KB correct
24 Correct 3 ms 1228 KB correct
25 Correct 2 ms 1228 KB correct
26 Correct 3 ms 1228 KB correct
27 Correct 3 ms 1228 KB correct
28 Correct 2 ms 1280 KB correct
29 Correct 1 ms 1228 KB correct
30 Correct 3 ms 1228 KB correct
31 Correct 3 ms 1228 KB correct
32 Correct 3 ms 1348 KB correct
33 Correct 3 ms 1228 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB correct
2 Correct 1 ms 1228 KB correct
3 Correct 1 ms 1228 KB correct
4 Correct 1 ms 1228 KB correct
5 Correct 1 ms 1228 KB correct
6 Correct 1 ms 1228 KB correct
7 Correct 1 ms 1228 KB correct
8 Correct 1 ms 1228 KB correct
9 Correct 1 ms 1228 KB correct
10 Correct 1 ms 1228 KB correct
11 Correct 1 ms 1228 KB correct
12 Correct 1 ms 1228 KB correct
13 Correct 1 ms 1228 KB correct
14 Correct 4 ms 1356 KB correct
15 Correct 4 ms 1356 KB correct
16 Correct 4 ms 1356 KB correct
17 Correct 3 ms 1356 KB correct
18 Correct 2 ms 1228 KB correct
19 Correct 4 ms 1356 KB correct
20 Correct 4 ms 1356 KB correct
21 Correct 3 ms 1356 KB correct
22 Correct 3 ms 1228 KB correct
23 Correct 3 ms 1228 KB correct
24 Correct 3 ms 1228 KB correct
25 Correct 2 ms 1228 KB correct
26 Correct 3 ms 1228 KB correct
27 Correct 3 ms 1228 KB correct
28 Correct 2 ms 1280 KB correct
29 Correct 1 ms 1228 KB correct
30 Correct 3 ms 1228 KB correct
31 Correct 3 ms 1228 KB correct
32 Correct 3 ms 1348 KB correct
33 Correct 3 ms 1228 KB correct
34 Correct 383 ms 3492 KB correct
35 Correct 387 ms 3028 KB correct
36 Correct 270 ms 2868 KB correct
37 Correct 22 ms 1356 KB correct
38 Correct 387 ms 3036 KB correct
39 Correct 319 ms 2748 KB correct
40 Correct 265 ms 3360 KB correct
41 Correct 30 ms 2496 KB correct
42 Correct 365 ms 2556 KB correct
43 Correct 228 ms 2244 KB correct
44 Correct 177 ms 2004 KB correct
45 Correct 212 ms 1964 KB correct
46 Correct 147 ms 1960 KB correct
47 Correct 68 ms 1604 KB correct
48 Correct 13 ms 1340 KB correct
49 Correct 22 ms 1356 KB correct
50 Correct 68 ms 1484 KB correct
51 Correct 213 ms 2052 KB correct
52 Correct 178 ms 1976 KB correct
53 Correct 179 ms 1836 KB correct
54 Correct 208 ms 2148 KB correct
55 Correct 189 ms 2124 KB correct
56 Correct 186 ms 2228 KB correct
57 Correct 185 ms 2140 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB correct
2 Correct 1 ms 1228 KB correct
3 Incorrect 455 ms 5268 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB correct
2 Correct 1 ms 1228 KB correct
3 Correct 1 ms 1228 KB correct
4 Correct 1 ms 1228 KB correct
5 Correct 1 ms 1228 KB correct
6 Correct 1 ms 1228 KB correct
7 Correct 1 ms 1228 KB correct
8 Correct 1 ms 1228 KB correct
9 Correct 1 ms 1228 KB correct
10 Correct 1 ms 1228 KB correct
11 Correct 1 ms 1228 KB correct
12 Correct 1 ms 1228 KB correct
13 Correct 1 ms 1228 KB correct
14 Correct 4 ms 1356 KB correct
15 Correct 4 ms 1356 KB correct
16 Correct 4 ms 1356 KB correct
17 Correct 3 ms 1356 KB correct
18 Correct 2 ms 1228 KB correct
19 Correct 4 ms 1356 KB correct
20 Correct 4 ms 1356 KB correct
21 Correct 3 ms 1356 KB correct
22 Correct 3 ms 1228 KB correct
23 Correct 3 ms 1228 KB correct
24 Correct 3 ms 1228 KB correct
25 Correct 2 ms 1228 KB correct
26 Correct 3 ms 1228 KB correct
27 Correct 3 ms 1228 KB correct
28 Correct 2 ms 1280 KB correct
29 Correct 1 ms 1228 KB correct
30 Correct 3 ms 1228 KB correct
31 Correct 3 ms 1228 KB correct
32 Correct 3 ms 1348 KB correct
33 Correct 3 ms 1228 KB correct
34 Correct 383 ms 3492 KB correct
35 Correct 387 ms 3028 KB correct
36 Correct 270 ms 2868 KB correct
37 Correct 22 ms 1356 KB correct
38 Correct 387 ms 3036 KB correct
39 Correct 319 ms 2748 KB correct
40 Correct 265 ms 3360 KB correct
41 Correct 30 ms 2496 KB correct
42 Correct 365 ms 2556 KB correct
43 Correct 228 ms 2244 KB correct
44 Correct 177 ms 2004 KB correct
45 Correct 212 ms 1964 KB correct
46 Correct 147 ms 1960 KB correct
47 Correct 68 ms 1604 KB correct
48 Correct 13 ms 1340 KB correct
49 Correct 22 ms 1356 KB correct
50 Correct 68 ms 1484 KB correct
51 Correct 213 ms 2052 KB correct
52 Correct 178 ms 1976 KB correct
53 Correct 179 ms 1836 KB correct
54 Correct 208 ms 2148 KB correct
55 Correct 189 ms 2124 KB correct
56 Correct 186 ms 2228 KB correct
57 Correct 185 ms 2140 KB correct
58 Correct 1 ms 1228 KB correct
59 Correct 1 ms 1228 KB correct
60 Incorrect 455 ms 5268 KB WA in grader: NO
61 Halted 0 ms 0 KB -