Submission #3365098


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 100005;
int n, fa[2 * N], size[2 * N], val[N];
ll tag[2 * N];
struct edge
{
	int a, b, c;
} e[N];
vector<int> g[2 * N];
bool operator<(const edge &x, const edge &y) { return x.c > y.c; }

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

void dfs(int u)
{
	if (u <= n) size[u] = 1;
	for (int v : g[u]) dfs(v), size[u] += size[v];
	for (int v : g[u]) tag[v] += 1ll * (size[u] - size[v]) * val[u];
}
void get(int u)
{
	for (int v : g[u]) tag[v] += tag[u], get(v);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c);
	sort(e + 1, e + n);
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1; i < n; i++)
	{
		int s = find(e[i].a), t = find(e[i].b);
		fa[n + i] = n + i, val[n + i] = e[i].c;
		fa[s] = fa[t] = n + i;
		g[n + i].push_back(s), g[n + i].push_back(t);
	}
	dfs(2 * n - 1);
	get(2 * n - 1);
	for (int i = 1; i <= n; i++) printf("%lld\n", tag[i]);
}

Submission Info

Submission Time
Task E - Black Cats Deployment
User luogu_bot3
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1014 Byte
Status WA
Exec Time 77 ms
Memory 20352 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:30:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:31:72: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i < n; i++) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c);
                                                                        ^

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 200 / 200 0 / 200 0 / 400
Status
AC × 3
AC × 10
AC × 4
WA × 5
AC × 15
WA × 17
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 8448 KB
00_example_02.txt AC 3 ms 8448 KB
00_example_03.txt AC 3 ms 8448 KB
s1_01.txt AC 4 ms 8448 KB
s1_02.txt AC 3 ms 8448 KB
s1_03.txt AC 3 ms 8448 KB
s1_04.txt AC 4 ms 8448 KB
s1_05.txt AC 3 ms 8448 KB
s1_06.txt AC 4 ms 8448 KB
s1_07.txt AC 4 ms 8448 KB
s2_08.txt WA 55 ms 13824 KB
s2_09.txt AC 28 ms 10752 KB
s2_10.txt AC 17 ms 9984 KB
s2_11.txt WA 64 ms 14720 KB
s2_12.txt WA 63 ms 14336 KB
s2_13.txt WA 56 ms 13440 KB
s2_14.txt WA 52 ms 13440 KB
s3_15.txt WA 65 ms 14208 KB
s3_16.txt AC 33 ms 10880 KB
s3_17.txt AC 21 ms 10112 KB
s3_18.txt AC 34 ms 11392 KB
s3_19.txt WA 75 ms 14976 KB
s3_20.txt WA 77 ms 14208 KB
s3_21.txt WA 75 ms 15232 KB
s3_22.txt WA 75 ms 15232 KB
s3_23.txt WA 72 ms 13824 KB
s3_24.txt WA 67 ms 13952 KB
s3_25.txt WA 72 ms 20352 KB
s3_26.txt WA 68 ms 13952 KB
s3_27.txt WA 70 ms 20352 KB
s3_28.txt WA 66 ms 13952 KB
s3_29.txt WA 68 ms 20352 KB