#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int N = 1001000;
pair<ll, int> dp[2][N];
vector<int> adj[N];
int a[N], ans = -1;
ll mn = INF;
void dfs(int v, int p = -1) {
dp[0][v] = dp[1][v] = { 0, -1 };
for (auto& x : adj[v]) {
if (x == p) continue;
dfs(x, v);
pair<ll, int> now = { dp[0][x].first + a[x], x };
dp[1][x] = max(dp[1][x], now);
if (dp[1][x] > dp[0][x]) swap(dp[1][x], dp[0][x]);
}
}
void dfs2(int v, int p = -1, ll w = 0) {
if (max(w, dp[0][v].first) < mn) {
mn = max(w, dp[0][v].first);
ans = v;
}
for (auto& x : adj[v]) {
if (x == p) continue;
if (dp[0][v].second == x) dfs2(x, v, dp[1][v].first + a[v]);
else dfs2(x, v, dp[0][v].first + a[v]);
}
}
int LocateCentre(int n, int p[], int s[], int d[]) {
for (int i = 0;i < n;i++) {
a[i] = p[i];
}
for (int i = 0;i < n - 1;i++) {
adj[s[i]].push_back(d[i]);
adj[d[i]].push_back(s[i]);
}
dfs(0);
dfs2(0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
35332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
35332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
35332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
35332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |