Submission #2666736
Source Code Expand
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct edge{ int u,v; long long w; edge(int a,int b,long long c):u(a),v(b),w(c){} }; long long lazy[N],res[N]; int n,p[N]; vector<vector<int> > sets; vector<edge> E; bool cmp(edge &a,edge &b){ return a.w<b.w; } void dsu(int i,int j,long long w){ for(int k=0;k<sets[i].size();k++){ res[sets[i][k]]+=lazy[i]-lazy[j]+w*sets[j].size(); p[sets[i][k]]=j; } for(int k=0;k<sets[i].size();k++){ sets[j].push_back(sets[i][k]); } sets[i].clear(); } int main(){ scanf("%d",&n); sets.assign(n+1,vector<int>()); for(int i=1;i<=n;i++){ p[i]=i; sets[i].push_back(i); } for(int i=1;i<n;i++){ int u,v; long long w; cin>>u>>v>>w; E.push_back(edge(u,v,w)); } sort(E.begin(),E.end(),cmp); reverse(E.begin(),E.end()); for(int i=0;i<E.size();i++){ int u=p[E[i].u]; int v=p[E[i].v]; int w=E[i].w; if(sets[u].size()>sets[v].size()){ swap(u,v); } lazy[v]+=w*sets[u].size(); dsu(u,v,w); } for(int i=1;i<=n;i++){ cout<<res[i]+lazy[p[i]]<<"\n"; } }
Submission Info
Submission Time | |
---|---|
Task | E - Black Cats Deployment |
User | vjudge5 |
Language | Bash (GNU bash v4.3.11) |
Score | 0 |
Code Size | 1046 Byte |
Status | RE |
Exec Time | 17 ms |
Memory | 1620 KB |
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 200 | 0 / 200 | 0 / 400 | ||||||||
Status |
|
|
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
Subtask1 | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt |
Subtask2 | 00_example_02.txt, s1_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s3_15.txt, s3_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s3_27.txt, s3_28.txt, s3_29.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | RE | 17 ms | 1620 KB |
00_example_02.txt | RE | 4 ms | 584 KB |
00_example_03.txt | RE | 4 ms | 584 KB |
s1_01.txt | RE | 4 ms | 584 KB |
s1_02.txt | RE | 4 ms | 592 KB |
s1_03.txt | RE | 4 ms | 592 KB |
s1_04.txt | RE | 4 ms | 584 KB |
s1_05.txt | RE | 4 ms | 580 KB |
s1_06.txt | RE | 4 ms | 584 KB |
s1_07.txt | RE | 4 ms | 580 KB |
s2_08.txt | RE | 4 ms | 584 KB |
s2_09.txt | RE | 4 ms | 592 KB |
s2_10.txt | RE | 4 ms | 588 KB |
s2_11.txt | RE | 4 ms | 584 KB |
s2_12.txt | RE | 4 ms | 584 KB |
s2_13.txt | RE | 4 ms | 584 KB |
s2_14.txt | RE | 4 ms | 584 KB |
s3_15.txt | RE | 4 ms | 584 KB |
s3_16.txt | RE | 4 ms | 580 KB |
s3_17.txt | RE | 4 ms | 580 KB |
s3_18.txt | RE | 4 ms | 584 KB |
s3_19.txt | RE | 4 ms | 584 KB |
s3_20.txt | RE | 4 ms | 584 KB |
s3_21.txt | RE | 4 ms | 580 KB |
s3_22.txt | RE | 4 ms | 592 KB |
s3_23.txt | RE | 4 ms | 584 KB |
s3_24.txt | RE | 4 ms | 584 KB |
s3_25.txt | RE | 4 ms | 584 KB |
s3_26.txt | RE | 4 ms | 580 KB |
s3_27.txt | RE | 4 ms | 584 KB |
s3_28.txt | RE | 4 ms | 584 KB |
s3_29.txt | RE | 4 ms | 584 KB |