Submission #3365120


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[2 * 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_bot5
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1018 Byte
Status AC
Exec Time 75 ms
Memory 20864 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 200 / 200 400 / 400
Status
AC × 3
AC × 10
AC × 9
AC × 32
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 4 ms 8448 KB
00_example_03.txt AC 4 ms 8448 KB
s1_01.txt AC 4 ms 8448 KB
s1_02.txt AC 5 ms 8448 KB
s1_03.txt AC 5 ms 8448 KB
s1_04.txt AC 4 ms 8576 KB
s1_05.txt AC 4 ms 8448 KB
s1_06.txt AC 4 ms 8448 KB
s1_07.txt AC 3 ms 6400 KB
s2_08.txt AC 56 ms 14080 KB
s2_09.txt AC 28 ms 11136 KB
s2_10.txt AC 17 ms 10112 KB
s2_11.txt AC 63 ms 15232 KB
s2_12.txt AC 63 ms 14720 KB
s2_13.txt AC 56 ms 13824 KB
s2_14.txt AC 53 ms 13824 KB
s3_15.txt AC 65 ms 14592 KB
s3_16.txt AC 34 ms 11136 KB
s3_17.txt AC 20 ms 10368 KB
s3_18.txt AC 34 ms 11776 KB
s3_19.txt AC 75 ms 15488 KB
s3_20.txt AC 74 ms 14720 KB
s3_21.txt AC 75 ms 15744 KB
s3_22.txt AC 75 ms 15744 KB
s3_23.txt AC 71 ms 14336 KB
s3_24.txt AC 66 ms 14336 KB
s3_25.txt AC 68 ms 20864 KB
s3_26.txt AC 66 ms 14464 KB
s3_27.txt AC 68 ms 20864 KB
s3_28.txt AC 66 ms 14464 KB
s3_29.txt AC 68 ms 20864 KB