luogu#P7973. [KSN2021] Binary Land
[KSN2021] Binary Land
Problem Description
You are given a graph with vertices. Each vertex has a weight and a value .
There is an undirected edge between two vertices if and only if .
You need to compute, for in order, the sum of values of all vertices in the connected component that contains vertex .
Input Format
The first line contains a positive integer .
The second line contains positive integers .
The third line contains positive integers .
Output Format
Output lines. The -th line contains an integer representing the sum of values of all vertices in the connected component that contains vertex .
3
2 1 1
20 30 10
60
60
60
4
5 4 4 5
10 20 30 40
10
20
30
40
5
1 2 1 7 11
20 10 30 100 100
60
60
60
200
200
Hint
Constraints
This problem uses bundled testdata.
- Subtask 1 (8 points): There is only one test case, with , , .
- Subtask 2 (13 points): Guaranteed .
- Subtask 3 (10 points): Guaranteed .
- Subtask 4 (4 points): Guaranteed .
- Subtask 5 (7 points): Guaranteed that there exists a non-negative integer such that .
- Subtask 6 (19 points): .
- Subtask 7 (39 points): No special restrictions.
For all testdata, , , .
Translated by ChatGPT 5