답안 #64450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64450 2018-08-04T13:48:59 Z IvanC Simurgh (IOI17_simurgh) C++17
51 / 100
270 ms 6460 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
 
const int MAXN = 501;
 
int adjMatrix[MAXN][MAXN],isRoyalRoad[MAXN*MAXN],dsu_parent[MAXN],N;
vi arestas_certas,arestas_dsu;
 
int dsu_find(int x){
	if(x == dsu_parent[x]) return x;
	return dsu_parent[x] = dsu_find(dsu_parent[x]);
}
 
void dsu_join(int x,int y){
	x = dsu_find(x);
	y = dsu_find(y);
	if(x == y) return;
	if(x > y) swap(x,y);
	dsu_parent[y] = x;
}
 
void dsu_reset(){
	for(int i = 0;i<N;i++) dsu_parent[i] = i;
}
 
void processa(int x){
 
	dsu_reset();
	arestas_dsu.clear();
 
	for(int i = 0;i<N;i++){
		if(i == x) continue;
		for(int j = 0;j<N;j++){
			if(j == x || adjMatrix[i][j] == -1) continue;
			if(dsu_find(i) != dsu_find(j)){
				dsu_join(i,j);
				arestas_dsu.push_back(adjMatrix[i][j]);
			}
		}
	}
 
	vector<vi> arestas_faltam;
	vi qual_pos;
 
	for(int i = 0;i<N;i++){
		if(i == x || dsu_find(i) != i) continue;
		vi novo_cjt;
		for(int j = 0;j<N;j++){
			if(j == x || adjMatrix[x][j] == -1 || isRoyalRoad[adjMatrix[x][j]] == 0) continue;
			if(dsu_find(j) == dsu_find(i)) novo_cjt.push_back(adjMatrix[x][j]);
		}
		qual_pos.push_back(arestas_dsu.size());
		arestas_dsu.push_back(novo_cjt[0]);
		arestas_faltam.push_back(novo_cjt);
	}
 
	for(int i = 0;i<arestas_faltam.size();i++){
 
		int maxv = 0;
		vi resultados;
 
		for(int j = 0;j<arestas_faltam[i].size();j++){
			arestas_dsu[qual_pos[i]] = arestas_faltam[i][j];
			resultados.push_back(count_common_roads(arestas_dsu));
			maxv = max(maxv,resultados.back());
		}
 
		for(int j = 0;j<arestas_faltam[i].size();j++){
			if(resultados[j] == maxv){
				arestas_certas.push_back(arestas_faltam[i][j]);
				isRoyalRoad[arestas_faltam[i][j]] = 1;
			}
			else{
				isRoyalRoad[arestas_faltam[i][j]] = 0;
			}
		}
 
	}
 
}
 
vi find_roads(int n, vi u, vi v) {
 
 	memset(isRoyalRoad,-1,sizeof(isRoyalRoad));
	memset(adjMatrix,-1,sizeof(adjMatrix));
	N = n;
 
	for(int i = 0;i<u.size();i++){
		adjMatrix[u[i]][v[i]] = i;
		adjMatrix[v[i]][u[i]] = i;
	}
 
	for(int i = 0;i<n;i++) processa(i);
 
	sort(arestas_certas.begin(),arestas_certas.end());
	arestas_certas.erase(unique(arestas_certas.begin(),arestas_certas.end()),arestas_certas.end());
 
	return arestas_certas;
 
}

Compilation message

simurgh.cpp: In function 'void processa(int)':
simurgh.cpp:60:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<arestas_faltam.size();i++){
                ~^~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:65:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0;j<arestas_faltam[i].size();j++){
                 ~^~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:71:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0;j<arestas_faltam[i].size();j++){
                 ~^~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'vi find_roads(int, vi, vi)':
simurgh.cpp:91:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<u.size();i++){
                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2296 KB correct
2 Correct 3 ms 2296 KB correct
3 Correct 4 ms 2464 KB correct
4 Correct 4 ms 2464 KB correct
5 Correct 4 ms 2464 KB correct
6 Correct 3 ms 2540 KB correct
7 Correct 4 ms 2540 KB correct
8 Correct 4 ms 2540 KB correct
9 Correct 4 ms 2540 KB correct
10 Correct 4 ms 2540 KB correct
11 Correct 3 ms 2540 KB correct
12 Correct 4 ms 2540 KB correct
13 Correct 4 ms 2540 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2296 KB correct
2 Correct 3 ms 2296 KB correct
3 Correct 4 ms 2464 KB correct
4 Correct 4 ms 2464 KB correct
5 Correct 4 ms 2464 KB correct
6 Correct 3 ms 2540 KB correct
7 Correct 4 ms 2540 KB correct
8 Correct 4 ms 2540 KB correct
9 Correct 4 ms 2540 KB correct
10 Correct 4 ms 2540 KB correct
11 Correct 3 ms 2540 KB correct
12 Correct 4 ms 2540 KB correct
13 Correct 4 ms 2540 KB correct
14 Correct 8 ms 2572 KB correct
15 Correct 7 ms 2572 KB correct
16 Correct 7 ms 2572 KB correct
17 Correct 6 ms 2572 KB correct
18 Correct 6 ms 2572 KB correct
19 Correct 5 ms 2572 KB correct
20 Correct 6 ms 2572 KB correct
21 Correct 8 ms 2572 KB correct
22 Correct 7 ms 2572 KB correct
23 Correct 8 ms 2572 KB correct
24 Correct 7 ms 2572 KB correct
25 Correct 4 ms 2572 KB correct
26 Correct 5 ms 2572 KB correct
27 Correct 7 ms 2572 KB correct
28 Correct 8 ms 2572 KB correct
29 Correct 6 ms 2572 KB correct
30 Correct 8 ms 2572 KB correct
31 Correct 7 ms 2572 KB correct
32 Correct 7 ms 2572 KB correct
33 Correct 8 ms 2572 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2296 KB correct
2 Correct 3 ms 2296 KB correct
3 Correct 4 ms 2464 KB correct
4 Correct 4 ms 2464 KB correct
5 Correct 4 ms 2464 KB correct
6 Correct 3 ms 2540 KB correct
7 Correct 4 ms 2540 KB correct
8 Correct 4 ms 2540 KB correct
9 Correct 4 ms 2540 KB correct
10 Correct 4 ms 2540 KB correct
11 Correct 3 ms 2540 KB correct
12 Correct 4 ms 2540 KB correct
13 Correct 4 ms 2540 KB correct
14 Correct 8 ms 2572 KB correct
15 Correct 7 ms 2572 KB correct
16 Correct 7 ms 2572 KB correct
17 Correct 6 ms 2572 KB correct
18 Correct 6 ms 2572 KB correct
19 Correct 5 ms 2572 KB correct
20 Correct 6 ms 2572 KB correct
21 Correct 8 ms 2572 KB correct
22 Correct 7 ms 2572 KB correct
23 Correct 8 ms 2572 KB correct
24 Correct 7 ms 2572 KB correct
25 Correct 4 ms 2572 KB correct
26 Correct 5 ms 2572 KB correct
27 Correct 7 ms 2572 KB correct
28 Correct 8 ms 2572 KB correct
29 Correct 6 ms 2572 KB correct
30 Correct 8 ms 2572 KB correct
31 Correct 7 ms 2572 KB correct
32 Correct 7 ms 2572 KB correct
33 Correct 8 ms 2572 KB correct
34 Correct 270 ms 2960 KB correct
35 Correct 243 ms 3180 KB correct
36 Correct 237 ms 3352 KB correct
37 Correct 44 ms 3352 KB correct
38 Correct 260 ms 3820 KB correct
39 Correct 243 ms 3940 KB correct
40 Correct 246 ms 4008 KB correct
41 Correct 244 ms 4424 KB correct
42 Correct 222 ms 4500 KB correct
43 Correct 185 ms 4500 KB correct
44 Correct 142 ms 4500 KB correct
45 Correct 210 ms 4628 KB correct
46 Correct 116 ms 4628 KB correct
47 Correct 79 ms 4628 KB correct
48 Correct 33 ms 4628 KB correct
49 Correct 53 ms 4628 KB correct
50 Correct 80 ms 4692 KB correct
51 Correct 158 ms 4772 KB correct
52 Correct 136 ms 4936 KB correct
53 Correct 147 ms 5216 KB correct
54 Correct 166 ms 5292 KB correct
55 Correct 166 ms 5292 KB correct
56 Correct 193 ms 5376 KB correct
57 Correct 176 ms 5480 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5480 KB correct
2 Correct 5 ms 5480 KB correct
3 Incorrect 189 ms 6460 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2296 KB correct
2 Correct 3 ms 2296 KB correct
3 Correct 4 ms 2464 KB correct
4 Correct 4 ms 2464 KB correct
5 Correct 4 ms 2464 KB correct
6 Correct 3 ms 2540 KB correct
7 Correct 4 ms 2540 KB correct
8 Correct 4 ms 2540 KB correct
9 Correct 4 ms 2540 KB correct
10 Correct 4 ms 2540 KB correct
11 Correct 3 ms 2540 KB correct
12 Correct 4 ms 2540 KB correct
13 Correct 4 ms 2540 KB correct
14 Correct 8 ms 2572 KB correct
15 Correct 7 ms 2572 KB correct
16 Correct 7 ms 2572 KB correct
17 Correct 6 ms 2572 KB correct
18 Correct 6 ms 2572 KB correct
19 Correct 5 ms 2572 KB correct
20 Correct 6 ms 2572 KB correct
21 Correct 8 ms 2572 KB correct
22 Correct 7 ms 2572 KB correct
23 Correct 8 ms 2572 KB correct
24 Correct 7 ms 2572 KB correct
25 Correct 4 ms 2572 KB correct
26 Correct 5 ms 2572 KB correct
27 Correct 7 ms 2572 KB correct
28 Correct 8 ms 2572 KB correct
29 Correct 6 ms 2572 KB correct
30 Correct 8 ms 2572 KB correct
31 Correct 7 ms 2572 KB correct
32 Correct 7 ms 2572 KB correct
33 Correct 8 ms 2572 KB correct
34 Correct 270 ms 2960 KB correct
35 Correct 243 ms 3180 KB correct
36 Correct 237 ms 3352 KB correct
37 Correct 44 ms 3352 KB correct
38 Correct 260 ms 3820 KB correct
39 Correct 243 ms 3940 KB correct
40 Correct 246 ms 4008 KB correct
41 Correct 244 ms 4424 KB correct
42 Correct 222 ms 4500 KB correct
43 Correct 185 ms 4500 KB correct
44 Correct 142 ms 4500 KB correct
45 Correct 210 ms 4628 KB correct
46 Correct 116 ms 4628 KB correct
47 Correct 79 ms 4628 KB correct
48 Correct 33 ms 4628 KB correct
49 Correct 53 ms 4628 KB correct
50 Correct 80 ms 4692 KB correct
51 Correct 158 ms 4772 KB correct
52 Correct 136 ms 4936 KB correct
53 Correct 147 ms 5216 KB correct
54 Correct 166 ms 5292 KB correct
55 Correct 166 ms 5292 KB correct
56 Correct 193 ms 5376 KB correct
57 Correct 176 ms 5480 KB correct
58 Correct 5 ms 5480 KB correct
59 Correct 5 ms 5480 KB correct
60 Incorrect 189 ms 6460 KB WA in grader: NO
61 Halted 0 ms 0 KB -