# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
235308 | ArshiaDadras | Zagrade (COI17_zagrade) | C++14 | 382 ms | 119548 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
map<int, int> mp1[N], mp2[N];
int n, cost1[N], cost2[N];
vector<int> adj[N];
long long ans;
void Swap(int u, int v) {
swap(mp1[u], mp1[v]);
swap(mp2[u], mp2[v]);
swap(cost1[u], cost1[v]);
swap(cost2[u], cost2[v]);
}
void dfs(int u, int par) {
int cost = cost1[u];
for (auto v: adj[u])
if (v ^ par) {
dfs(v, u);
bool rev = mp1[u].size() + mp2[u].size() < mp1[v].size() + mp2[v].size();
if (rev)
Swap(u, v);
for (auto [x, k]: mp1[v])
if (mp2[u].count(x + cost1[v] - cost2[u]))
ans += 1LL * k * mp2[u][x + cost1[v] - cost2[u]];
for (auto [x, k]: mp2[v])
if (mp1[u].count(x + cost2[v] - cost1[u]))
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |