Submission #2668083
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
long long n, u, v, w, res[100010], par[100010], lazy[100010], ans = 1e18;
vector <pair<int, pair <int, int> > > E;
vector <int> ccnt[100010];
int main() {
scanf("%I64d", &n);
for(int i = 1; i < n; i++) {
scanf("%I64d%I64d%I64d", &u, &v, &w);
E.push_back({w, {u, v}});
}
for(int i = 1; i <= n; i++) {
par[i] = i, lazy[i] = res[i] = 0;
ccnt[i].push_back(i);
}
sort(E.begin(), E.end(), greater<pair<int, pair<int, int> > >());
for(int i = 0; i < n-1; i++) {
int u = E[i].se.fi, v = E[i].se.se, w = E[i].fi, p1 = par[u], p2 = par[v];
if(ccnt[p1] < ccnt[p2]) swap(p1, p2);
int s1 = ccnt[p1].size(), s2 = ccnt[p2].size(); lazy[p1] += s2 * w;
for(int j = 0; j < s2; j++) v = ccnt[p2][j], par[v] = p1, res[v] += s1 * w + lazy[p2] - lazy[p1], ccnt[p1].push_back(v);
}
for(int i = 1; i <= n; i++) printf("%I64d\n", res[i] + lazy[par[i]]);
}
Submission Info
Submission Time
2018-06-15 01:28:57+0900
Task
E - Black Cats Deployment
User
vjudge5
Language
C++14 (GCC 5.4.1)
Score
200
Code Size
938 Byte
Status
WA
Exec Time
215 ms
Memory
20724 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:11:19: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
scanf("%I64d", &n);
^
./Main.cpp:13:38: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
scanf("%I64d%I64d%I64d", &u, &v, &w);
^
./Main.cpp:13:38: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=]
./Main.cpp:13:38: warning: format ‘%d’ expects argument of type ‘int*’, but argument 4 has type ‘long long int*’ [-Wformat=]
./Main.cpp:27:69: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
for(int i = 1; i <= n; i++) printf("%I64d\n", res[i] + lazy[par[i]]);
^
./Main.cpp:11:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with...
Judge Result
Set Name
Sample
Subtask1
Subtask2
All
Score / Max Score
0 / 0
0 / 200
200 / 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
AC
4 ms
4480 KB
00_example_02.txt
AC
3 ms
4352 KB
00_example_03.txt
AC
3 ms
4352 KB
s1_01.txt
WA
4 ms
4352 KB
s1_02.txt
WA
3 ms
4352 KB
s1_03.txt
WA
3 ms
4352 KB
s1_04.txt
WA
4 ms
4480 KB
s1_05.txt
WA
4 ms
4480 KB
s1_06.txt
WA
4 ms
4480 KB
s1_07.txt
AC
3 ms
4352 KB
s2_08.txt
AC
138 ms
17268 KB
s2_09.txt
AC
67 ms
10488 KB
s2_10.txt
AC
39 ms
7676 KB
s2_11.txt
AC
157 ms
18164 KB
s2_12.txt
AC
159 ms
18036 KB
s2_13.txt
AC
166 ms
20468 KB
s2_14.txt
AC
166 ms
20724 KB
s3_15.txt
WA
178 ms
16628 KB
s3_16.txt
WA
89 ms
10488 KB
s3_17.txt
WA
51 ms
7548 KB
s3_18.txt
WA
88 ms
10232 KB
s3_19.txt
WA
203 ms
17780 KB
s3_20.txt
WA
209 ms
19188 KB
s3_21.txt
WA
205 ms
18292 KB
s3_22.txt
WA
204 ms
17652 KB
s3_23.txt
WA
215 ms
20724 KB
s3_24.txt
WA
204 ms
20084 KB
s3_25.txt
WA
187 ms
16756 KB
s3_26.txt
WA
204 ms
19572 KB
s3_27.txt
WA
187 ms
16628 KB
s3_28.txt
WA
203 ms
19828 KB
s3_29.txt
WA
188 ms
16884 KB