Submission #338763

# Submission time Handle Problem Language Result Execution time Memory
338763 2020-12-23T20:57:53 Z wind_reaper Dreaming (IOI13_dreaming) C++17
0 / 100
64 ms 14444 KB
#include "dreaming.h"
#include <bits/stdc++.h>
 
using namespace std; 

const int MAXN = 1e5 + 5, INF = INT_MAX;  	
pair<int, int> root, leaf[2]; 
vector<pair<int, int>> adj[MAXN];
int ddist[MAXN][2]; 
bool vis[MAXN]; 
int comps[MAXN]; 
void dfs(int node, int p, int dist, int idx){
	vis[node] = 1; 
	leaf[idx] = max(leaf[idx], {dist, node}); 
	ddist[node][idx] = dist; 

	root = min(root, {max(ddist[node][0], ddist[node][1]), node}); 

	for(auto& [v, wt] : adj[node]){
		if(v == p) 
			continue; 

		dfs(v, node, dist + wt, idx); 
	}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for(int i = 0; i < M; i++){
		adj[A[i]].emplace_back(make_pair(B[i], T[i])); 
		adj[B[i]].emplace_back(make_pair(A[i], T[i])); 
	}
	int c = 0; 
	int max_d = 0; 
	for(int i = 0; i < N; i++){
		if(vis[i] == 1) 
			continue; 

		leaf[0] = leaf[1] = {INT_MIN, INT_MIN}; 

		dfs(i, i, 0, 0); 
		dfs(leaf[0].second, -1, 0, 1); 
		root = {INF, i}; 
		dfs(leaf[1].second, -1, 0, 0);
		max_d = max(max_d, leaf[0].first); 
		comps[c++] = root.first; 
	}

	sort(comps, comps + c); 
	return max({max_d, comps[c-1] + comps[c-2] + L, comps[c-2] + comps[c-3] + 2*L}); 
}
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13164 KB Output is correct
2 Correct 64 ms 14444 KB Output is correct
3 Correct 37 ms 10476 KB Output is correct
4 Correct 9 ms 4460 KB Output is correct
5 Correct 8 ms 3692 KB Output is correct
6 Correct 15 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13164 KB Output is correct
2 Correct 64 ms 14444 KB Output is correct
3 Correct 37 ms 10476 KB Output is correct
4 Correct 9 ms 4460 KB Output is correct
5 Correct 8 ms 3692 KB Output is correct
6 Correct 15 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13164 KB Output is correct
2 Correct 64 ms 14444 KB Output is correct
3 Correct 37 ms 10476 KB Output is correct
4 Correct 9 ms 4460 KB Output is correct
5 Correct 8 ms 3692 KB Output is correct
6 Correct 15 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 6252 KB Output is correct
2 Correct 26 ms 6124 KB Output is correct
3 Correct 28 ms 6124 KB Output is correct
4 Correct 26 ms 6124 KB Output is correct
5 Correct 30 ms 6124 KB Output is correct
6 Correct 29 ms 6252 KB Output is correct
7 Correct 29 ms 6252 KB Output is correct
8 Correct 29 ms 6148 KB Output is correct
9 Correct 27 ms 5996 KB Output is correct
10 Correct 28 ms 6252 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 7 ms 3948 KB Output is correct
13 Correct 7 ms 3948 KB Output is correct
14 Correct 7 ms 4076 KB Output is correct
15 Correct 7 ms 3948 KB Output is correct
16 Correct 9 ms 4076 KB Output is correct
17 Correct 7 ms 3948 KB Output is correct
18 Correct 8 ms 3948 KB Output is correct
19 Correct 7 ms 3948 KB Output is correct
20 Incorrect 2 ms 2668 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13164 KB Output is correct
2 Correct 64 ms 14444 KB Output is correct
3 Correct 37 ms 10476 KB Output is correct
4 Correct 9 ms 4460 KB Output is correct
5 Correct 8 ms 3692 KB Output is correct
6 Correct 15 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13164 KB Output is correct
2 Correct 64 ms 14444 KB Output is correct
3 Correct 37 ms 10476 KB Output is correct
4 Correct 9 ms 4460 KB Output is correct
5 Correct 8 ms 3692 KB Output is correct
6 Correct 15 ms 5228 KB Output is correct
7 Incorrect 2 ms 2668 KB Output isn't correct
8 Halted 0 ms 0 KB -