#P16265. [蓝桥杯 2026 省 Python B 组] 蓝小圈

    ID: 18285 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>并查集2026蓝桥杯省赛

[蓝桥杯 2026 省 Python B 组] 蓝小圈

Problem Description

The phone screen lights up faintly, and the icon of the social platform “Blue Little Circle” flickers slightly. Xiao Lan, the backend architect of the platform, is staring at the traffic monitoring dashboard where the numbers keep jumping.

To improve user engagement, the product manager proposes a brand-new “circle interaction” feature. There are NN user nodes in the system. Initially, every user’s “activity” is 00, and all users are strangers to each other, with no social connections.

After the feature goes online, the backend log will record QQ user action commands in order. The commands are as follows:

  1. Add friends: user XX and user YY follow each other, and the social circles they belong to become connected. If they are already in the same social circle, ignore this operation.
  2. Post a personal update: user XX posts a personal update, and their activity increases by AA.
  3. Circle trending topic: user XX starts a trending topic. This topic has a strong spreading effect, causing all users in the same social circle as XX (i.e., directly or indirectly connected through friendships) to have their activity increased by AA.
  4. Data query: the operations team requests the current activity value of user XX for analyzing user quality.

As the number of users grows rapidly, frequent social interaction requests put huge pressure on the server’s core computing module. As Xiao Lan’s assistant, please take over the log processing unit and output all query results in order.

Input Format

The first line contains two positive integers NN and QQ, representing the total number of platform users and the total number of action log entries.

The next QQ lines each describe one specific action command, following one of the four formats below:

  • 11 XX YY: perform “add friends”, connecting the social circles of users XX and YY.
  • 22 XX AA: perform “personal update”, increasing user XX’s activity by AA.
  • 33 XX AA: perform “circle trending topic”, increasing the activity of all users in XX’s social circle by AA.
  • 44 XX: perform “data query”, querying the current activity of user XX.

Output Format

For each “data query” command, output a single line containing an integer, representing the current activity value of the target user.

3 6
1 1 2
1 1 3
2 1 5
3 2 5
4 1
4 2
10
5

Hint

[Test Case Scale and Conventions]

For 30%30\% of the testdata, 1≤N≤10001 \leq N \leq 1000, 1≤Q≤10001 \leq Q \leq 1000.

For all testdata, 1≤N≤2×1051 \leq N \leq 2 \times 10^5, 1≤Q≤2×1051 \leq Q \leq 2 \times 10^5, 1≤X,Y≤N1 \leq X, Y \leq N, 1≤A≤1091 \leq A \leq 10^9. It is guaranteed that the testdata contains at least one type 44 “data query” command.

Translated by ChatGPT 5