Submission #136572

# Submission time Handle Problem Language Result Execution time Memory
136572 2019-07-25T15:25:26 Z rondojim Simurgh (IOI17_simurgh) C++17
30 / 100
3000 ms 3960 KB
#include "simurgh.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 510;
 
int dsu[nax];
int m,n;
vector<pair<int,int>> g[nax];
vector<int> u,v;
 
int find(int u){
	return u == dsu[u] ? u : dsu[u] = find(dsu[u]);
}
 
bool good(vector<int> ans){
	for(int i=0;i<n;i++)
		dsu[i] = i;
	for(int i=0;i<ans.size();i++){
		int id = ans[i];
		int a = u[id];
		int b = v[id];
		if(find(a) == find(b))
			continue;
		dsu[find(b)] = find(a);
	}
	for(int i=0;i<n;i++)
		if(find(i) != find(0))
			return 0;
	return 1;
}
 
vector<int> find_roads(int N, vector<int> U, vector<int> V) {
	vector<int> ans;
	u = U;
	v = V;
	n = N;
	m = u.size();
 
	for(int i=0;i<n;i++)
		dsu[i] = i;
 
	int lst;
	for(int i=0;i<m;i++){
		int a = u[i];
		int b = v[i];
		g[a].push_back({b,i});
		g[b].push_back({a,i});
		if(find(a) == find(b))
			continue;
		ans.push_back(i);
		dsu[find(b)] = find(a);
	}
	lst = count_common_roads(ans);
	for(int i=0;i<ans.size();i++){
		int id = ans[i];
		int a = u[id];
		int b = v[id];
		for(int j=0;j<m;j++){
			ans[i] = j;
			if(good(ans) == 1){
				int r = count_common_roads(ans);
				if(r < lst){
					ans[i] = id;
					break;
				}
				if(r > lst){
					lst = r;
					break;
				}
			}
			ans[i] = id;
		}
	}
	// for(int i : ans)
	// 	printf("%d ", i);
	// printf("\n");
	return ans;
}

Compilation message

simurgh.cpp: In function 'bool good(std::vector<int>)':
simurgh.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:59:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
simurgh.cpp:61:7: warning: unused variable 'a' [-Wunused-variable]
   int a = u[id];
       ^
simurgh.cpp:62:7: warning: unused variable 'b' [-Wunused-variable]
   int b = v[id];
       ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Correct 2 ms 376 KB correct
5 Correct 2 ms 376 KB correct
6 Correct 2 ms 376 KB correct
7 Correct 2 ms 376 KB correct
8 Correct 2 ms 376 KB correct
9 Correct 2 ms 256 KB correct
10 Correct 2 ms 376 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 2 ms 252 KB correct
13 Correct 2 ms 256 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Correct 2 ms 376 KB correct
5 Correct 2 ms 376 KB correct
6 Correct 2 ms 376 KB correct
7 Correct 2 ms 376 KB correct
8 Correct 2 ms 376 KB correct
9 Correct 2 ms 256 KB correct
10 Correct 2 ms 376 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 2 ms 252 KB correct
13 Correct 2 ms 256 KB correct
14 Correct 41 ms 504 KB correct
15 Correct 36 ms 376 KB correct
16 Correct 43 ms 376 KB correct
17 Correct 36 ms 428 KB correct
18 Correct 13 ms 376 KB correct
19 Correct 34 ms 452 KB correct
20 Correct 32 ms 376 KB correct
21 Correct 32 ms 376 KB correct
22 Correct 7 ms 376 KB correct
23 Correct 6 ms 380 KB correct
24 Correct 5 ms 376 KB correct
25 Correct 5 ms 376 KB correct
26 Correct 6 ms 376 KB correct
27 Correct 16 ms 508 KB correct
28 Correct 10 ms 376 KB correct
29 Correct 8 ms 376 KB correct
30 Correct 4 ms 376 KB correct
31 Correct 5 ms 376 KB correct
32 Correct 6 ms 376 KB correct
33 Correct 5 ms 376 KB correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Correct 2 ms 376 KB correct
5 Correct 2 ms 376 KB correct
6 Correct 2 ms 376 KB correct
7 Correct 2 ms 376 KB correct
8 Correct 2 ms 376 KB correct
9 Correct 2 ms 256 KB correct
10 Correct 2 ms 376 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 2 ms 252 KB correct
13 Correct 2 ms 256 KB correct
14 Correct 41 ms 504 KB correct
15 Correct 36 ms 376 KB correct
16 Correct 43 ms 376 KB correct
17 Correct 36 ms 428 KB correct
18 Correct 13 ms 376 KB correct
19 Correct 34 ms 452 KB correct
20 Correct 32 ms 376 KB correct
21 Correct 32 ms 376 KB correct
22 Correct 7 ms 376 KB correct
23 Correct 6 ms 380 KB correct
24 Correct 5 ms 376 KB correct
25 Correct 5 ms 376 KB correct
26 Correct 6 ms 376 KB correct
27 Correct 16 ms 508 KB correct
28 Correct 10 ms 376 KB correct
29 Correct 8 ms 376 KB correct
30 Correct 4 ms 376 KB correct
31 Correct 5 ms 376 KB correct
32 Correct 6 ms 376 KB correct
33 Correct 5 ms 376 KB correct
34 Execution timed out 3086 ms 1528 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 2 ms 376 KB correct
3 Execution timed out 3077 ms 3960 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB correct
2 Correct 2 ms 376 KB correct
3 Correct 2 ms 256 KB correct
4 Correct 2 ms 376 KB correct
5 Correct 2 ms 376 KB correct
6 Correct 2 ms 376 KB correct
7 Correct 2 ms 376 KB correct
8 Correct 2 ms 376 KB correct
9 Correct 2 ms 256 KB correct
10 Correct 2 ms 376 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 2 ms 252 KB correct
13 Correct 2 ms 256 KB correct
14 Correct 41 ms 504 KB correct
15 Correct 36 ms 376 KB correct
16 Correct 43 ms 376 KB correct
17 Correct 36 ms 428 KB correct
18 Correct 13 ms 376 KB correct
19 Correct 34 ms 452 KB correct
20 Correct 32 ms 376 KB correct
21 Correct 32 ms 376 KB correct
22 Correct 7 ms 376 KB correct
23 Correct 6 ms 380 KB correct
24 Correct 5 ms 376 KB correct
25 Correct 5 ms 376 KB correct
26 Correct 6 ms 376 KB correct
27 Correct 16 ms 508 KB correct
28 Correct 10 ms 376 KB correct
29 Correct 8 ms 376 KB correct
30 Correct 4 ms 376 KB correct
31 Correct 5 ms 376 KB correct
32 Correct 6 ms 376 KB correct
33 Correct 5 ms 376 KB correct
34 Execution timed out 3086 ms 1528 KB Time limit exceeded
35 Halted 0 ms 0 KB -