답안 #167473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167473 2019-12-08T16:13:10 Z nikatamliani 꿈 (IOI13_dreaming) C++14
18 / 100
86 ms 14836 KB
# include "dreaming.h"
# include <bits/stdc++.h>
using namespace std; 
const int N = 2e5 + 10;
int fix[N];
vector < int > pts;
vector < pair < int , int > > edges[N];
void dfs(int x, int p, vector < int >& dist){
	fix[x] = 1;
	pts.push_back(x);
	for(int i = 0; i < edges[x].size(); i ++){
		if(edges[x][i].first != p){
			dist[edges[x][i].first] = dist[x] + edges[x][i].second;
			dfs(edges[x][i].first, x, dist);
		}
	}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
	vector < int > dist_a(N, 0), dist_b(N, 0), cen;
	for(int i = 0; i < M; i ++){
		edges[A[i]].push_back(make_pair(B[i], T[i]));
		edges[B[i]].push_back(make_pair(A[i], T[i]));
	}
	for(int i = 0; i < N; i ++){
		if(fix[i] != 1){
			pts.clear();
			dist_a[i] = 0;  
			dfs(i, -1, dist_a);
			int a = pts[0];
			for(int i = 0; i < pts.size(); i ++){
				if(dist_a[pts[i]] > dist_a[a]) a = pts[i];
			}
			pts.clear();
			dist_a[a] = 0;
			dfs(a, -1, dist_a);
			int b = pts[0];
			for(int i = 0; i < pts.size(); i ++){
				if(dist_a[pts[i]] > dist_a[b]) b = pts[i]; 
			}
			if(M == N - 1) return dist_a[b];
			pts.clear();
			dist_b[b] = 0;
			dfs(b, -1, dist_b);
			int res = 1e9;
			for(int i = 0; i < pts.size(); i ++){
				res = min(res, max(dist_a[pts[i]], dist_b[pts[i]]));
			}
			cen.push_back(res);
			pts.clear();
		}
	}
 	sort(cen.rbegin(), cen.rend());
    int res = 0;
    if(cen.size() >= 2) res = cen[0] + cen[1] + L;
    if(cen.size() >= 3) res = max(res, cen[1] + cen[2] + 2 * L); 
    return res;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int, std::vector<int>&)':
dreaming.cpp:11:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < edges[x].size(); i ++){
                 ~~^~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < pts.size(); i ++){
                   ~~^~~~~~~~~~~~
dreaming.cpp:37:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < pts.size(); i ++){
                   ~~^~~~~~~~~~~~
dreaming.cpp:45:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < pts.size(); i ++){
                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 9308 KB Output is correct
2 Correct 47 ms 9324 KB Output is correct
3 Correct 36 ms 9208 KB Output is correct
4 Correct 35 ms 9208 KB Output is correct
5 Correct 36 ms 9336 KB Output is correct
6 Correct 46 ms 9852 KB Output is correct
7 Correct 67 ms 9564 KB Output is correct
8 Correct 49 ms 9208 KB Output is correct
9 Correct 33 ms 9208 KB Output is correct
10 Correct 36 ms 9336 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 13 ms 6900 KB Output is correct
13 Correct 14 ms 6900 KB Output is correct
14 Correct 13 ms 6872 KB Output is correct
15 Correct 13 ms 6820 KB Output is correct
16 Correct 14 ms 6900 KB Output is correct
17 Correct 13 ms 6772 KB Output is correct
18 Correct 14 ms 6900 KB Output is correct
19 Correct 13 ms 7000 KB Output is correct
20 Correct 6 ms 4984 KB Output is correct
21 Correct 6 ms 4988 KB Output is correct
22 Correct 7 ms 5112 KB Output is correct
23 Correct 13 ms 6900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -