Submission #2668102


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("%lld", &n);
	for(int i = 1; i < n; i++) {
		scanf("%lld%lld%lld", &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("%lld\n", res[i] + lazy[par[i]]);
}

Submission Info

Submission Time
Task E - Black Cats Deployment
User Megumi_Tadokoro
Language C++14 (GCC 5.4.1)
Score 200
Code Size 975 Byte
Status WA
Exec Time 81 ms
Memory 15476 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:11:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
                   ^
./Main.cpp:13:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &u, &v, &w);
                                    ^

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 0 / 200 200 / 200 0 / 400
Status
AC × 3
AC × 4
WA × 6
AC × 9
AC × 11
WA × 21
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 2 ms 4352 KB
00_example_03.txt AC 3 ms 4352 KB
s1_01.txt WA 3 ms 4352 KB
s1_02.txt WA 3 ms 4352 KB
s1_03.txt WA 3 ms 4352 KB
s1_04.txt WA 3 ms 4352 KB
s1_05.txt WA 3 ms 4352 KB
s1_06.txt WA 3 ms 4480 KB
s1_07.txt AC 3 ms 4352 KB
s2_08.txt AC 61 ms 12276 KB
s2_09.txt AC 30 ms 7928 KB
s2_10.txt AC 17 ms 6268 KB
s2_11.txt AC 65 ms 12532 KB
s2_12.txt AC 67 ms 12276 KB
s2_13.txt AC 75 ms 14708 KB
s2_14.txt AC 74 ms 14964 KB
s3_15.txt WA 63 ms 12148 KB
s3_16.txt WA 33 ms 8312 KB
s3_17.txt WA 18 ms 6268 KB
s3_18.txt WA 31 ms 7928 KB
s3_19.txt WA 70 ms 12660 KB
s3_20.txt WA 76 ms 14068 KB
s3_21.txt WA 72 ms 13300 KB
s3_22.txt WA 70 ms 12660 KB
s3_23.txt WA 81 ms 15476 KB
s3_24.txt WA 72 ms 14836 KB
s3_25.txt WA 56 ms 11764 KB
s3_26.txt WA 72 ms 14452 KB
s3_27.txt WA 56 ms 11764 KB
s3_28.txt WA 72 ms 14580 KB
s3_29.txt WA 57 ms 12020 KB