Submission #3370151


Source Code Expand

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

const int N = 100005;
typedef long long ll;
int n, tot = 1, u[N], v[N], nxt[2 * N], fst[N], to[2 * N], size[N];
ll s[N], w[N], res;

void dfs(int u, int fa)
{
	size[u] = 1;
	for (int i = fst[u]; i; i = nxt[i])
		if (to[i] != fa)
		{
			dfs(to[i], u);
			size[u] += size[to[i]];
			if (size[to[i]] * 2 != n)
				w[i >> 1] = (s[u] - s[to[i]]) / (2 * size[to[i]] - n);
		}
}

void bf(int u, int fa)
{
	size[u] = 1;
	for (int i = fst[u]; i; i = nxt[i])
		if (to[i] != fa)
			bf(to[i], u), res += size[to[i]] * w[i >> 1], size[u] += size[to[i]];
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		scanf("%d%d", u + i, v + i);
		nxt[++tot] = fst[u[i]]; fst[u[i]] = tot; to[tot] = v[i];
		nxt[++tot] = fst[v[i]]; fst[v[i]] = tot; to[tot] = u[i];
	}
	for (int i = 1; i <= n; i++) scanf("%lld", s + i);
	dfs(1, 0);
	for (int i = 1; i < n; i++)
		if (!w[i])
		{
			bf(u[i], v[i]), bf(v[i], u[i]);
			w[i] = (s[u[i]] - res) / size[v[i]];
		}
	for (int i = 1; i < n; i++) printf("%lld\n", w[i]);
	return 0;
}

Submission Info

Submission Time
Task D - Ancient Tree Record
User luogu_bot2
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1061 Byte
Status AC
Exec Time 52 ms
Memory 10240 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:32:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:35:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", u + i, v + i);
                              ^
./Main.cpp:39:51: 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("%lld", s + i);
                                                   ^

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 300 / 300 200 / 200 300 / 300
Status
AC × 3
AC × 14
AC × 11
AC × 48
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt
Subtask2 00_example_02.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.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, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s3_27.txt, s3_28.txt, s3_29.txt, s3_30.txt, s3_31.txt, s3_32.txt, s3_33.txt, s3_34.txt, s3_35.txt, s3_36.txt, s3_37.txt, s3_38.txt, s3_39.txt, s3_40.txt, s3_41.txt, s3_42.txt, s3_43.txt, s3_44.txt, s3_45.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 2304 KB
00_example_02.txt AC 2 ms 2304 KB
00_example_03.txt AC 1 ms 2304 KB
s1_01.txt AC 28 ms 6656 KB
s1_02.txt AC 39 ms 8576 KB
s1_03.txt AC 3 ms 2560 KB
s1_04.txt AC 32 ms 7552 KB
s1_05.txt AC 6 ms 3200 KB
s1_06.txt AC 48 ms 10240 KB
s1_07.txt AC 49 ms 10240 KB
s1_08.txt AC 48 ms 10240 KB
s1_09.txt AC 1 ms 2304 KB
s1_10.txt AC 1 ms 2304 KB
s1_11.txt AC 1 ms 2304 KB
s1_12.txt AC 1 ms 2304 KB
s1_13.txt AC 1 ms 2304 KB
s2_14.txt AC 25 ms 4224 KB
s2_15.txt AC 34 ms 4992 KB
s2_16.txt AC 43 ms 5632 KB
s2_17.txt AC 43 ms 5632 KB
s2_18.txt AC 43 ms 5632 KB
s2_19.txt AC 43 ms 5632 KB
s2_20.txt AC 1 ms 2304 KB
s2_21.txt AC 1 ms 2304 KB
s2_22.txt AC 1 ms 2304 KB
s2_23.txt AC 2 ms 2304 KB
s3_24.txt AC 27 ms 4096 KB
s3_25.txt AC 39 ms 4864 KB
s3_26.txt AC 3 ms 2432 KB
s3_27.txt AC 32 ms 4480 KB
s3_28.txt AC 6 ms 2688 KB
s3_29.txt AC 49 ms 5504 KB
s3_30.txt AC 48 ms 5504 KB
s3_31.txt AC 48 ms 5632 KB
s3_32.txt AC 52 ms 8064 KB
s3_33.txt AC 50 ms 9472 KB
s3_34.txt AC 46 ms 5632 KB
s3_35.txt AC 46 ms 5632 KB
s3_36.txt AC 1 ms 2304 KB
s3_37.txt AC 1 ms 2304 KB
s3_38.txt AC 1 ms 2304 KB
s3_39.txt AC 1 ms 2304 KB
s3_40.txt AC 29 ms 4096 KB
s3_41.txt AC 41 ms 4864 KB
s3_42.txt AC 3 ms 2432 KB
s3_43.txt AC 52 ms 5632 KB
s3_44.txt AC 51 ms 5504 KB
s3_45.txt AC 52 ms 5504 KB