Box Witch
Time limit3sMemory limit512 MB
A graph with N nodes and unit-capacity edges is modified by edge insertions and deletions, and after each change you must report the max flow from node 1 to node N.
- Level
Medium7 of 10
- Topics
- Graph, Dynamic programming, Implementation, Brute force
- Solved
- No attempts yet
Problem
H.N.ELLY, the Box Witch, is an avid fan of a certain video site. Miki Sayaka wondered whether the Box Witch's strength changes with the transfer speed from that video site at any given time. So she wants to investigate the past transfer speeds (the amount of data transferred per unit time) from the video site to the computer owned by the Box Witch.
You are given the structure of the initial internet network and queries describing subsequent changes to the network structure. For each change, find the transfer speed from the video site to the computer owned by the Box Witch immediately after the change.
The internet is regarded as consisting of several transfer devices. The lines connecting them can send information in both directions, and the maximum transfer speed of each line is 1. The network always carries data so as to maximize the transfer speed of the data sent from the video site to the Box Witch.
Input
The input is given in the following format.
N E Q
F1 T1
F2 T2
…
FE TE
M1 A1 B1
M2 A2 B2
…
MQ AQ BQ
N is the number of transfer devices, including the video site and the computer owned by the Box Witch. The transfer device numbered 1 is the video site, and the transfer device numbered N is the computer owned by the Box Witch. E is the number of pairs of transfer devices connected in the initial state, and Q is the number of times the internet changes. The initial internet is represented by Fi and Ti being connected in both directions with transfer speed 1.
The changes to the network are given in chronological order. The j-th change represents that Aj and Bj have been connected if Mj is 1, and that the connection between Aj and Bj has been removed if Mj is 2.
Output
Output the transfer speed from the video site to the computer owned by the Box Witch immediately after each change.
Constraints
2≤N≤5000≤E≤20,0001≤Q≤1,0001≤Fi≤N, 1≤Ti≤N, Fi≠Ti (1≤i≤E)- All pairs
{Fi,Ti}are distinct. 1≤Mj≤2, 1≤Aj≤N, 1≤Bj≤N, Aj≠Bj (1≤j≤Q)- At every stage of the network the following holds: any
2transfer devices are connected by at most1line. - There is no query that connects
2transfer devices that are already connected, nor any query that disconnects2transfer devices that are not connected by a line.