# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1125281 | SulA | Traffic (IOI10_traffic) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC target("popcnt")
using namespace __gnu_pbds;
using namespace std;
using ordered_set = tree<int, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;
#define popcount __builtin_popcountll
#define all(a) (a).begin(), (a).end()
vector<int> adj[1'000'000];
long long sum[1'000'000], dp[1'000'000], out[1'000'000];
void dfs(int u = 0, int p = -1) {
for (int v : adj[u]) if (v != p) {
dfs(v, u);
sum[u] += sum[v];
dp[u] += dp[v] + sum[v];
}
}
void dfs2(int u = 0, int p = -1) {
for (int v : adj[u]) if (v != p) {
out[v] = (out[u] + dp[u]) - (dp[v] + sum[v]) + (sum[0] - sum[v]);
dfs2(v, u);
}
}
int LocateCentre(int n, vector<int> p, vector<int> s, vector<int> d) {