#P8710. [蓝桥杯 2020 省 AB1] 网络分析
[蓝桥杯 2020 省 AB1] 网络分析
Problem Description
Xiaoming is doing a network experiment.
He sets up computers, called nodes, used to send, receive, and store data.
Initially, all nodes are independent, and there are no connections.
Xiaoming can use network cables to connect two nodes. After they are connected, the two nodes can communicate with each other. If there is a cable connection between two nodes, they are called adjacent.
Sometimes Xiaoming tests the current network. He sends a message from a certain node. The message is sent to each adjacent node, and then those nodes forward it to their own adjacent nodes, until all nodes that are directly or indirectly adjacent have received the message. All nodes that send or receive the message will store it. Each message is stored only once.
Given Xiaoming’s process of connecting and testing, compute the total size of messages stored on each node.
Input Format
The first line contains two integers and , representing the number of nodes and the number of operations. Nodes are numbered from to .
The next lines each contain three integers, describing an operation.
If an operation is 1 a b, it means connecting node and node with a network cable. When , it means adding a self-loop, which has no real effect on the network.
If an operation is 2 p t, it means sending a message of size from node .
Output Format
Output one line containing integers, separated by one space, representing the total size of messages stored on nodes to after all operations are completed.
4 8
1 1 2
2 1 10
2 3 5
1 4 1
2 2 2
1 1 2
1 2 4
2 2 1
13 13 5 3
Hint
For of the test cases, and .
For of the test cases, and .
For of the test cases, and .
For all test cases, , , and .
Lanqiao Cup 2020, First Round of the Provincial Contest, Group A Problem J (Group B Problem J).
Translated by ChatGPT 5