Submission #167471

# Submission time Handle Problem Language Result Execution time Memory
167471 2019-12-08T16:05:13 Z nikatamliani Dreaming (IOI13_dreaming) C++14
18 / 100
88 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, 0, 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, 0, 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, 0, 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 ++){
                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 8868 KB Output is correct
2 Correct 41 ms 8824 KB Output is correct
3 Correct 36 ms 8824 KB Output is correct
4 Correct 46 ms 8824 KB Output is correct
5 Correct 52 ms 8824 KB Output is correct
6 Correct 45 ms 9360 KB Output is correct
7 Correct 42 ms 8952 KB Output is correct
8 Correct 38 ms 8824 KB Output is correct
9 Correct 36 ms 8740 KB Output is correct
10 Correct 46 ms 8952 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 14 ms 6900 KB Output is correct
13 Correct 16 ms 6872 KB Output is correct
14 Correct 14 ms 6900 KB Output is correct
15 Correct 14 ms 6900 KB Output is correct
16 Correct 14 ms 6900 KB Output is correct
17 Correct 17 ms 6772 KB Output is correct
18 Correct 15 ms 6900 KB Output is correct
19 Correct 14 ms 6900 KB Output is correct
20 Correct 6 ms 4984 KB Output is correct
21 Correct 6 ms 4988 KB Output is correct
22 Correct 6 ms 5112 KB Output is correct
23 Correct 14 ms 6900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 14836 KB Output isn't correct
2 Halted 0 ms 0 KB -