#SRD0000121. Những cây cầu (Bridges)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những cây cầu (Bridges)
Bridges
Source: APIO
Version: Phuoc Hung OJ Extended
Problem Statement
A city has islands, numbered to , joined by undirected bridges, numbered to . Bridge joins islands and supports vehicles of weight at most . Parallel bridges may exist and have distinct indices; self-loops do not occur.
Process operations in order:
1 b r: set the weight limit of bridge to exactly ; this is assignment, not addition.2 s w: a car of weight starts at island . Output how many islands are reachable from , including itself, using only bridges whose weight limits are at least .
An update takes effect immediately and influences subsequent queries.
Input
- The first line contains .
- Each of the next lines contains for bridge .
- The next line contains .
- Each of the next lines describes an operation
1 b ror2 s w, in chronological order.
Output
For every type-2 operation, print one integer on its own line, in chronological order. Type-1 operations produce no output.
Subtasks
- Subtask 1 (13 points): , , ; , ; ; ; for type-1 operations; type-1 operations require .
- Subtask 2 (16 points): , , ; , ; ; ; for type-1 operations; type-1 operations require . , , for (a chain).
- Subtask 3 (17 points): , , ; , ; ; ; for type-1 operations; type-1 operations require . , ; ; , for (a complete binary tree).
- Subtask 4 (14 points): , , ; , ; ; ; for type-1 operations; type-1 operations require . All operations have (no updates).
- Subtask 5 (13 points): , , ; , ; ; ; for type-1 operations; type-1 operations require . and the undirected graph initially forms a tree.
- Subtask 6 (27 points): , , ; , ; ; ; for type-1 operations; type-1 operations require .
Examples
Sample 1
Input
3 4
1 2 5
2 3 2
3 1 4
2 3 8
5
2 1 5
1 4 1
2 2 5
1 1 1
2 3 2
Output
3
2
3
Explanation
In sample 1, a weight- car at island can reach all three islands using bridges 1 and 4. After bridge 4 is set to , a weight- car at island can reach only islands . After bridge 1 is set to , a weight- car at island can still reach all three islands through bridges 2 and 3.
Sample 2
Input
7 8
1 2 5
1 6 5
2 3 5
2 7 5
3 4 5
4 5 5
5 6 5
6 7 5
12
2 1 6
1 1 1
2 1 2
1 2 3
2 2 2
1 5 2
1 3 1
2 2 4
2 4 2
1 8 1
2 1 1
2 1 3
Output
1
7
7
5
7
7
4
Explanation
In sample 2, every weight-limit update is applied before the following queries. The seven type-2 queries return . Initially, a weight- car cannot traverse any bridge because all limits are , hence the first answer is .