답안 #218876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218876 2020-04-03T00:18:02 Z bigg 꿈 (IOI13_dreaming) C++14
18 / 100
70 ms 14452 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
int n, m, l;
vector<pair<int, int> > grafo[112345];
vector<int> comp[112345];
int compid[112345];
int altura[112345];
int centro[112345], maxraio[112345];
int marc1[112345], marc2[112345], marc3[112345];
int maxd, maxdi, qtdcomp, cf, cfi;

void dfs1(int x){
	marc1[x] = 1;
	comp[qtdcomp].push_back(x);
	for(int i = 0; i < grafo[x].size(); i++){
		int viz = grafo[x][i].first;
		if(!marc1[viz]){
			altura[viz] = altura[x] + grafo[x][i].second;
			if(altura[viz] >= maxd){
				maxd = altura[viz];
				maxdi = viz;
			}
			dfs1(viz);
		}


	}

}
void dfs2(int x){
	marc2[x] = 1;
	
	for(int i = 0; i < grafo[x].size(); i++){
		int viz = grafo[x][i].first;
		if(!marc2[viz]){
			altura[viz] = altura[x] + grafo[x][i].second;
			maxd = max(maxd, altura[viz]);
			dfs2(viz);
		}


	}

}
bool cmp(int a, int b){
	return a > b;
}
void dfs3(int x){
	marc3[x] = 1;
	
	for(int i = 0; i < grafo[x].size(); i++){
		int viz = grafo[x][i].first;
		if(!marc3[viz]){
			altura[viz] = altura[x] + grafo[x][i].second;
			maxd = max(maxd, altura[viz]);
			dfs3(viz);
		}


	}

}
int ans = 0;


int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	n = N, m = M, l = L;
	
	for(int i = 0; i < m; i++){
		//int a, b, t;
		//scanf("%d %d", &a, &b, &t);
		grafo[A[i]].push_back(make_pair(B[i], T[i]));
		grafo[B[i]].push_back(make_pair(A[i], T[i]));

	}
		//printf("%d\n", n);
	for(int i = 0; i < n; i++){
	
		if(!marc1[i]){
			maxd = 0;

			dfs1(i);
			altura[maxdi] = 0;
			maxd = 0;
			dfs2(maxdi);
			int centrodesse = 1e9 + 7, cdi;
			for(int j = 0; j < comp[qtdcomp].size(); j++){
				if(abs(altura[comp[qtdcomp][j]] - maxd/2) <=  centrodesse){
					cdi = comp[qtdcomp][j];
					centrodesse = abs(altura[comp[qtdcomp][j]] - maxd/2);
				}
			}
			centro[qtdcomp] = cdi;
			ans = max(maxd, ans);
			maxd = 0;
			altura[cdi] = 0;
			dfs3(cdi);

			maxraio[qtdcomp] = maxd;

			qtdcomp++;
		}



	}
	
	sort(maxraio, maxraio + qtdcomp, cmp);
	//printf("%d\n", maxraio[cfi]);
	if(qtdcomp > 1){
		ans = max(ans, maxraio[0] + maxraio[1] + l);
		if(qtdcomp > 2){
			ans = max(ans, maxraio[1] + maxraio[2] + 2*l);
		}
	}
	if(n == 1) return 0;
    return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs1(int)':
dreaming.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < grafo[x].size(); i++){
                 ~~^~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int)':
dreaming.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < grafo[x].size(); i++){
                 ~~^~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs3(int)':
dreaming.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < grafo[x].size(); i++){
                 ~~^~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:88:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = 0; j < comp[qtdcomp].size(); j++){
                   ~~^~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:94:20: warning: 'cdi' may be used uninitialized in this function [-Wmaybe-uninitialized]
    centro[qtdcomp] = cdi;
    ~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 14452 KB Output is correct
2 Correct 59 ms 14452 KB Output is correct
3 Correct 48 ms 11636 KB Output is correct
4 Correct 15 ms 7168 KB Output is correct
5 Correct 13 ms 6528 KB Output is correct
6 Correct 21 ms 7808 KB Output is correct
7 Correct 8 ms 5632 KB Output is correct
8 Correct 34 ms 9216 KB Output is correct
9 Correct 43 ms 10232 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 62 ms 11768 KB Output is correct
12 Correct 70 ms 13068 KB Output is correct
13 Incorrect 8 ms 5760 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 14452 KB Output is correct
2 Correct 59 ms 14452 KB Output is correct
3 Correct 48 ms 11636 KB Output is correct
4 Correct 15 ms 7168 KB Output is correct
5 Correct 13 ms 6528 KB Output is correct
6 Correct 21 ms 7808 KB Output is correct
7 Correct 8 ms 5632 KB Output is correct
8 Correct 34 ms 9216 KB Output is correct
9 Correct 43 ms 10232 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 62 ms 11768 KB Output is correct
12 Correct 70 ms 13068 KB Output is correct
13 Incorrect 8 ms 5760 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 14452 KB Output is correct
2 Correct 59 ms 14452 KB Output is correct
3 Correct 48 ms 11636 KB Output is correct
4 Correct 15 ms 7168 KB Output is correct
5 Correct 13 ms 6528 KB Output is correct
6 Correct 21 ms 7808 KB Output is correct
7 Correct 8 ms 5632 KB Output is correct
8 Correct 34 ms 9216 KB Output is correct
9 Correct 43 ms 10232 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 62 ms 11768 KB Output is correct
12 Correct 70 ms 13068 KB Output is correct
13 Incorrect 8 ms 5760 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 12032 KB Output is correct
2 Correct 38 ms 12032 KB Output is correct
3 Correct 39 ms 12024 KB Output is correct
4 Correct 38 ms 12024 KB Output is correct
5 Correct 53 ms 11900 KB Output is correct
6 Correct 40 ms 12408 KB Output is correct
7 Correct 40 ms 12280 KB Output is correct
8 Correct 38 ms 11832 KB Output is correct
9 Correct 36 ms 11768 KB Output is correct
10 Correct 38 ms 12152 KB Output is correct
11 Correct 7 ms 5632 KB Output is correct
12 Correct 18 ms 11136 KB Output is correct
13 Correct 19 ms 11136 KB Output is correct
14 Correct 19 ms 11136 KB Output is correct
15 Correct 19 ms 11136 KB Output is correct
16 Correct 18 ms 11136 KB Output is correct
17 Correct 19 ms 10880 KB Output is correct
18 Correct 19 ms 11136 KB Output is correct
19 Correct 19 ms 11136 KB Output is correct
20 Correct 8 ms 5760 KB Output is correct
21 Correct 8 ms 5632 KB Output is correct
22 Correct 8 ms 5888 KB Output is correct
23 Correct 18 ms 11136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 14452 KB Output is correct
2 Correct 59 ms 14452 KB Output is correct
3 Correct 48 ms 11636 KB Output is correct
4 Correct 15 ms 7168 KB Output is correct
5 Correct 13 ms 6528 KB Output is correct
6 Correct 21 ms 7808 KB Output is correct
7 Correct 8 ms 5632 KB Output is correct
8 Correct 34 ms 9216 KB Output is correct
9 Correct 43 ms 10232 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 62 ms 11768 KB Output is correct
12 Correct 70 ms 13068 KB Output is correct
13 Incorrect 8 ms 5760 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 14452 KB Output is correct
2 Correct 59 ms 14452 KB Output is correct
3 Correct 48 ms 11636 KB Output is correct
4 Correct 15 ms 7168 KB Output is correct
5 Correct 13 ms 6528 KB Output is correct
6 Correct 21 ms 7808 KB Output is correct
7 Correct 8 ms 5632 KB Output is correct
8 Correct 34 ms 9216 KB Output is correct
9 Correct 43 ms 10232 KB Output is correct
10 Correct 8 ms 5632 KB Output is correct
11 Correct 62 ms 11768 KB Output is correct
12 Correct 70 ms 13068 KB Output is correct
13 Incorrect 8 ms 5760 KB Output isn't correct