Submission #2666775
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define int long long int n; vector<pair<int, pair<int, int> > > d; int par[100005]; long long res[100005]; int lazy[100005]; vector<int> child[100005]; void Union(int u, int v, int w) { if (child[par[u]].size() > child[par[v]].size()) { swap(u, v); } int k = par[u]; lazy[par[v]] += w*child[k].size(); for (int i = 0; i < child[k].size(); i++) { par[child[k][i]] = par[v]; res[child[k][i]] += w*child[par[v]].size() - lazy[par[v]] + lazy[k]; } for (int i = 0; i < child[k].size(); i++) { child[par[v]].push_back(child[k][i]); } lazy[k] = 0; child[k].clear(); } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i < n; i++) { int x, y, l; cin >> x >> y >> l; d.push_back({l,{x,y}}); } for (int i = 1; i <= n; i++) { child[i].push_back(i); par[i] = i; lazy[i] = 0; } sort(d.begin(), d.end()); memset(res, 0, sizeof res); memset(lazy, 0, sizeof lazy); reverse(d.begin(), d.end()); for (int i = 0; i < n-1; i++) { Union(d[i].second.first, d[i].second.second, d[i].first); } for (int i = 1; i <= n; i++) { cout << res[i] + lazy[par[i]] << endl; } }
Submission Info
Submission Time | |
---|---|
Task | E - Black Cats Deployment |
User | vjudge5 |
Language | C++14 (GCC 5.4.1) |
Score | 800 |
Code Size | 1341 Byte |
Status | AC |
Exec Time | 220 ms |
Memory | 19696 KB |
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | 200 / 200 | 400 / 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 | AC | 3 ms | 4352 KB |
00_example_02.txt | AC | 3 ms | 4352 KB |
00_example_03.txt | AC | 3 ms | 4352 KB |
s1_01.txt | AC | 4 ms | 4352 KB |
s1_02.txt | AC | 4 ms | 4480 KB |
s1_03.txt | AC | 4 ms | 4352 KB |
s1_04.txt | AC | 5 ms | 4480 KB |
s1_05.txt | AC | 4 ms | 4480 KB |
s1_06.txt | AC | 5 ms | 4480 KB |
s1_07.txt | AC | 3 ms | 4352 KB |
s2_08.txt | AC | 174 ms | 13552 KB |
s2_09.txt | AC | 87 ms | 8948 KB |
s2_10.txt | AC | 54 ms | 6648 KB |
s2_11.txt | AC | 198 ms | 14192 KB |
s2_12.txt | AC | 205 ms | 15088 KB |
s2_13.txt | AC | 215 ms | 18800 KB |
s2_14.txt | AC | 212 ms | 19312 KB |
s3_15.txt | AC | 183 ms | 13936 KB |
s3_16.txt | AC | 92 ms | 9204 KB |
s3_17.txt | AC | 55 ms | 6904 KB |
s3_18.txt | AC | 90 ms | 8820 KB |
s3_19.txt | AC | 206 ms | 15088 KB |
s3_20.txt | AC | 211 ms | 15984 KB |
s3_21.txt | AC | 208 ms | 15472 KB |
s3_22.txt | AC | 206 ms | 14704 KB |
s3_23.txt | AC | 219 ms | 19696 KB |
s3_24.txt | AC | 212 ms | 18928 KB |
s3_25.txt | AC | 191 ms | 13680 KB |
s3_26.txt | AC | 220 ms | 18800 KB |
s3_27.txt | AC | 191 ms | 13680 KB |
s3_28.txt | AC | 211 ms | 18160 KB |
s3_29.txt | AC | 191 ms | 13680 KB |