Submission #427667

# Submission time Handle Problem Language Result Execution time Memory
427667 2021-06-14T18:31:35 Z shubham20_03 Traffic (IOI10_traffic) C++17
0 / 100
16 ms 23816 KB
#include <bits/stdc++.h>
#include "traffic.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)

vector<int> adj[1000000];
int tot_peo[1000000], ans[1000000], peo[1000000];

// refer kartik arora's dp on trees youtube videos
// idea is taken from his tree distance ii video

void dfs1(int u, int p = -1) {
	tot_peo[u] = peo[u];
	for (int v : adj[u])
		if (v != p) {
			dfs1(v, u);
			tot_peo[u] += tot_peo[v];
		}
}

void dfs2(int u, int p = -1) {
	ans[u] = 0;
	for (int v : adj[u])
		if (v != p)
			ans[u] = max(ans[u], tot_peo[v]);

	if (p != -1)
		ans[u] = max(ans[u], tot_peo[0] - tot_peo[u]);

	for (int v : adj[u])
		if (v != p)
			dfs2(v, u);
}

int LocateCentre(int N, int P[], int S[], int D[]) {
	for (int i = 0; i < N - 1; i++) {
		adj[S[i]].push_back(D[i]);
		adj[D[i]].push_back(S[i]);
	}

	for (int i = 0; i < N; i++)
		peo[i] = P[i];

	dfs1(0);
	dfs2(0);

	int mn = 1e18;
	for (int i = 0; i < N; i++)
		mn = min(mn, ans[i]);

	return mn;
}

Compilation message

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:47:11: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   47 |  int mn = 1e18;
      |           ^~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Incorrect 14 ms 23816 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Incorrect 14 ms 23816 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Incorrect 14 ms 23816 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23756 KB Output is correct
2 Incorrect 14 ms 23816 KB Output isn't correct
3 Halted 0 ms 0 KB -