Submission #306509

# Submission time Handle Problem Language Result Execution time Memory
306509 2020-09-25T18:22:59 Z tengiz05 Dreaming (IOI13_dreaming) C++17
0 / 100
95 ms 17016 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1e5+5;
bool used[N];
int depth[N];
int dp[N];
vector<pair<int, int>> edges[N];
vector<int> a[N];
// dfs for calculating dp. (dp[i] - maximum depth)
void dfs(int u, int p){
	used[u] = true;
	dp[u] = 0;
	a[u].push_back(0);a[u].push_back(0);
	for(auto X : edges[u]){
		int v = X.first;
		int cost = X.second;
		if(v == p)continue;
		dfs(v, u);
		dp[u] = max(dp[u], dp[v]+cost);
		a[u].push_back(dp[v]+cost);
	}
	sort(a[u].begin(), a[u].end());
	reverse(a[u].begin(), a[u].end());
}
 
//dfs for rerooting
int mn;
void dfs2(int u, int p, int T){
	int dpu = dp[u];
	for(auto X : edges[u]){
		int v = X.first;
		int cost = X.second;
		if(v == p)continue;
		int tmp = dp[v];
		if(dp[v]+cost == a[u][0])dp[u] = a[u][1];
		if(u != p)dp[u] = max(dp[u], dp[p] + T);
		dp[v] = max(dp[v], dp[u] + cost);
		mn = min(mn, dp[v]);
		dfs2(v, u, cost);
		dp[v] = tmp;
		dp[u] = dpu;
	}
}
 
//calculate best center for the tree
int calculate_center(int u){
	dfs(u, u);
	mn = dp[u];
	dfs2(u, u ,0);
	return mn;
}
int travelTime(int _N, int M, int L, int A[], int B[], int T[]) {
	n = _N;
	for(int i=0;i<M;i++){
		edges[A[i]].push_back({B[i], T[i]});
		edges[B[i]].push_back({A[i], T[i]});
	}
	vector<int> v;
	for(int i=0;i<n;i++){
		if(!used[i]){
			v.push_back(calculate_center(i));
		}
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	if(v.size()-1 == 1){
		return a[0][0] + a[0][1];
	}
	else {
		int m = 0;
		for(int i=0;i<n;i++){
			m = max(m, a[i][0]+a[i][1]);
		}
		return max(v[0]+v[1]+L, max(m, ((v.size()>=3)? v[1]+v[2]+2*L : 0)));
	}
}
# Verdict Execution time Memory Grader output
1 Correct 92 ms 17016 KB Output is correct
2 Correct 95 ms 16632 KB Output is correct
3 Correct 59 ms 14584 KB Output is correct
4 Correct 14 ms 6784 KB Output is correct
5 Incorrect 12 ms 6016 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 17016 KB Output is correct
2 Correct 95 ms 16632 KB Output is correct
3 Correct 59 ms 14584 KB Output is correct
4 Correct 14 ms 6784 KB Output is correct
5 Incorrect 12 ms 6016 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 17016 KB Output is correct
2 Correct 95 ms 16632 KB Output is correct
3 Correct 59 ms 14584 KB Output is correct
4 Correct 14 ms 6784 KB Output is correct
5 Incorrect 12 ms 6016 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 10996 KB Output is correct
2 Correct 50 ms 10996 KB Output is correct
3 Correct 49 ms 10996 KB Output is correct
4 Correct 49 ms 10996 KB Output is correct
5 Correct 53 ms 10996 KB Output is correct
6 Correct 53 ms 11636 KB Output is correct
7 Correct 51 ms 11252 KB Output is correct
8 Correct 48 ms 10876 KB Output is correct
9 Correct 51 ms 10868 KB Output is correct
10 Correct 50 ms 11252 KB Output is correct
11 Correct 4 ms 4992 KB Output is correct
12 Correct 21 ms 9080 KB Output is correct
13 Correct 21 ms 9080 KB Output is correct
14 Correct 20 ms 9112 KB Output is correct
15 Correct 21 ms 9080 KB Output is correct
16 Correct 20 ms 9080 KB Output is correct
17 Correct 21 ms 9080 KB Output is correct
18 Correct 21 ms 9080 KB Output is correct
19 Correct 20 ms 9080 KB Output is correct
20 Incorrect 5 ms 4992 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 17016 KB Output is correct
2 Correct 95 ms 16632 KB Output is correct
3 Correct 59 ms 14584 KB Output is correct
4 Correct 14 ms 6784 KB Output is correct
5 Incorrect 12 ms 6016 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 92 ms 17016 KB Output is correct
2 Correct 95 ms 16632 KB Output is correct
3 Correct 59 ms 14584 KB Output is correct
4 Correct 14 ms 6784 KB Output is correct
5 Incorrect 12 ms 6016 KB Output isn't correct
6 Halted 0 ms 0 KB -