Submission #407399

# Submission time Handle Problem Language Result Execution time Memory
407399 2021-05-18T21:32:10 Z peuch Simurgh (IOI17_simurgh) C++11
30 / 100
3000 ms 5000 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1010;

int n, m;
vector<int> u, v;

vector<int> ar[MAXN], id[MAXN];
int marc[MAXN];
int grp[200000];
int cnt[200000];

int rep[MAXN], tam[MAXN];

vector<int> getPath(int cur, int fim, int x);
vector<int> getST(vector<int> base);
bool uni(int a, int b);
int find(int a);

vector<int> find_roads(int _n, vector<int> _u, vector<int> _v) {
	n = _n;
	u = _u, v = _v;
	m = u.size();
	
	for(int i = 0; i < u.size(); i++){
		ar[u[i]].push_back(v[i]);
		id[u[i]].push_back(i);
		ar[v[i]].push_back(u[i]);
		id[v[i]].push_back(i);
	}
	
	for(int i = 0; i < u.size(); i++){
		if(grp[i] != 0) continue;
//		printf("Calculating: %d\n", i);
		
		for(int j = 0; j < n; j++) marc[j] = 0;
		vector<int> path = getPath(u[i], v[i], i);
		
		
		if(path.empty()) {
//			printf("\tBridge\n");
			grp[i] = 1;
			continue;
		}
		
//		printf("\tCycle: %d ", i);
//		for(int j = 0; j < path.size(); j++)
//			printf("%d ", path[j]);
//		printf("\n");
		
		vector<int> r = getST(path);
		path.push_back(i);
		
		int maxi = 0;
		bool flag = false;
		for(int j = 0; j < path.size(); j++){
			if(grp[path[j]] != 0){
				if(flag) continue;
				if(grp[path[j]] == 1) continue;
				flag = true;
			}
			
			vector<int> test = r;
			for(int k = 0; k < path.size(); k++)
				if(k != j) test.push_back(path[k]);
			
			cnt[j] = count_common_roads(test);
			maxi = max(maxi, cnt[j]);
			
//			printf("Tested: %d -> %d\n", path[j], cnt[j]);
		}	
		for(int j = 0; j < path.size(); j++){
			if(grp[path[j]] != 0) continue;
			if(cnt[j] == maxi) grp[path[j]] = -1;
			if(cnt[j] != maxi) grp[path[j]] = 1;
		}
	}
	vector<int> ans;
	for(int i = 0; i < m; i++)
		if(grp[i] == 1) ans.push_back(i);
	
//	for(int i = 0; i < ans.size(); i++){
//		printf("%d ", ans[i]);
//	}
//	printf("\n");
	
	return ans;
}

vector<int> getPath(int cur, int fim, int x){
	marc[cur] = 1;
	vector<int> ret;
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		if(marc[viz]) continue;
		if(id[cur][i] == x) continue;
		ret = getPath(viz, fim, x);
		if(ret.empty() && viz != fim) continue;
		ret.push_back(id[cur][i]);
		return ret;
	}
	return ret;
}

vector<int> getST(vector<int> base){
	vector<int> ret;
	for(int i = 0; i < n; i++){
		tam[i] = 1;
		rep[i] = i;
	}
	for(int i = 0; i < base.size(); i++)
		uni(u[base[i]], v[base[i]]);
	for(int i = 0; i < m; i++)
		if(uni(u[i], v[i])) ret.push_back(i);
	return ret;
}

bool uni(int a, int b){
	a = find(a);
	b = find(b);
	if(a == b) return 0;
	if(tam[a] < tam[b]) swap(a, b);
	tam[a] += tam[b];
	rep[b] = a;
	return 1;
}

int find(int a){
	if(a == rep[a]) return a;
	return rep[a] = find(rep[a]);
}
/*
5 7
0 1
1 2
2 3
3 4
0 2
1 3
4 2
1 3 4 6
*/

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i = 0; i < u.size(); i++){
      |                 ~~^~~~~~~~~~
simurgh.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for(int i = 0; i < u.size(); i++){
      |                 ~~^~~~~~~~~~
simurgh.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for(int j = 0; j < path.size(); j++){
      |                  ~~^~~~~~~~~~~~~
simurgh.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    for(int k = 0; k < path.size(); k++)
      |                   ~~^~~~~~~~~~~~~
simurgh.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int j = 0; j < path.size(); j++){
      |                  ~~^~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> getPath(int, int, int)':
simurgh.cpp:95:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |  for(int i = 0; i < ar[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> getST(std::vector<int>)':
simurgh.cpp:113:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |  for(int i = 0; i < base.size(); i++)
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 352 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 352 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
14 Correct 21 ms 440 KB correct
15 Correct 21 ms 444 KB correct
16 Correct 21 ms 332 KB correct
17 Correct 15 ms 436 KB correct
18 Correct 4 ms 332 KB correct
19 Correct 17 ms 440 KB correct
20 Correct 15 ms 436 KB correct
21 Correct 13 ms 436 KB correct
22 Correct 9 ms 332 KB correct
23 Correct 7 ms 420 KB correct
24 Correct 7 ms 332 KB correct
25 Correct 1 ms 332 KB correct
26 Correct 8 ms 352 KB correct
27 Correct 7 ms 332 KB correct
28 Correct 3 ms 332 KB correct
29 Correct 1 ms 332 KB correct
30 Correct 7 ms 332 KB correct
31 Correct 7 ms 352 KB correct
32 Correct 7 ms 420 KB correct
33 Correct 8 ms 332 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 352 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
14 Correct 21 ms 440 KB correct
15 Correct 21 ms 444 KB correct
16 Correct 21 ms 332 KB correct
17 Correct 15 ms 436 KB correct
18 Correct 4 ms 332 KB correct
19 Correct 17 ms 440 KB correct
20 Correct 15 ms 436 KB correct
21 Correct 13 ms 436 KB correct
22 Correct 9 ms 332 KB correct
23 Correct 7 ms 420 KB correct
24 Correct 7 ms 332 KB correct
25 Correct 1 ms 332 KB correct
26 Correct 8 ms 352 KB correct
27 Correct 7 ms 332 KB correct
28 Correct 3 ms 332 KB correct
29 Correct 1 ms 332 KB correct
30 Correct 7 ms 332 KB correct
31 Correct 7 ms 352 KB correct
32 Correct 7 ms 420 KB correct
33 Correct 8 ms 332 KB correct
34 Execution timed out 3066 ms 2088 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Execution timed out 3052 ms 5000 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 352 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
14 Correct 21 ms 440 KB correct
15 Correct 21 ms 444 KB correct
16 Correct 21 ms 332 KB correct
17 Correct 15 ms 436 KB correct
18 Correct 4 ms 332 KB correct
19 Correct 17 ms 440 KB correct
20 Correct 15 ms 436 KB correct
21 Correct 13 ms 436 KB correct
22 Correct 9 ms 332 KB correct
23 Correct 7 ms 420 KB correct
24 Correct 7 ms 332 KB correct
25 Correct 1 ms 332 KB correct
26 Correct 8 ms 352 KB correct
27 Correct 7 ms 332 KB correct
28 Correct 3 ms 332 KB correct
29 Correct 1 ms 332 KB correct
30 Correct 7 ms 332 KB correct
31 Correct 7 ms 352 KB correct
32 Correct 7 ms 420 KB correct
33 Correct 8 ms 332 KB correct
34 Execution timed out 3066 ms 2088 KB Time limit exceeded
35 Halted 0 ms 0 KB -