Submission #674304

#TimeUsernameProblemLanguageResultExecution timeMemory
674304lamRace (IOI11_race)C++14
0 / 100
7 ms14420 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; const int maxn = 2e5 + 10; int n,k; map<int,int> mp[maxn]; int id[maxn],d[maxn]; vector <pair<int,int>> adj[maxn]; int ans[maxn]; void dfs(int x, int p, int depth) { ans[x]=0; mp[id[x]][depth]++; for (int i=0; i<(int)adj[x].size(); i++) { int v = adj[x][i].ff; int w=adj[x][i].ss; if (v==p) continue; dfs(v,x,depth+w); if (mp[id[i]].size()<mp[id[x]].size()) { for (pair<int,int> j: mp[id[i]]) { ans[x] += mp[id[x]][k - (j.ff - depth) +depth]*j.ss; mp[id[x]][j.ff]+=j.ss; } } else { for (pair<int,int> j: mp[id[x]]) { ans[x] += mp[id[i]][k - (j.ff - depth) +depth]*j.ss; mp[id[i]][j.ff]+=j.ss; } id[x]=id[i]; } } } int best_path(int N, int K, int H[][2], int L[]) { n=N; k=K; for (int i=1; i<=n; i++) id[i]=i; for (int i=0; i<n-1; i++) { int u=H[i][0]; int v=H[i][1]; u++; v++; adj[u].push_back({v,L[i]}); adj[v].push_back({u,L[i]}); } dfs(1,1,0); int res=0LL; for (int i=1; i<=n; i++) res+=ans[i]; return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...