Influence
Time limit1.5sMemory limit1024 MB
Given a graph with hub cities and point updates to passenger counts, report each queried hub's total passengers reachable without passing through another hub.
- Level
Medium7 of 10
- Topics
- Graph, DFS, Implementation
- Solved
- No attempts yet
Problem
In a distant country there are n cities numbered from 1 to n. Airlines run flights every day in both directions between m pairs of different cities. Some cities are hubs, and airlines give them extra attention and resources. Each city has some number of potential passengers, and that number can change over time.

Figure 1: Illustration of the first input. The current influence of city 3 is 22, and the current influence of city 6 is 8.
For a hub city a, its influence is the total number of potential passengers who are either in city a or can reach city a by a sequence of flights without passing through any other hub city (and without starting from another hub city).
You are given the flight network, which hub cities are marked, and the initial number of potential passengers in each city. You are also given q events, each of one of the following types:
1 a pa: the number of potential passengers in city a changes to pa.2 a: report the current influence of hub city a.
Answer every event of the second type.
Input
The first line contains natural numbers n and m, the number of cities and the number of routes. The next line contains n integers k1, k2, ..., kn, where kj is 1 if city j is a hub and 0 otherwise. The next line contains n integers p1, p2, ..., pn, where pj is the initial number of potential passengers in city j (). Each of the next m lines contains two different natural numbers aj and bj (), the cities joined directly by a route. The network is not necessarily connected.
The next line contains the natural number q, the number of events. Each of the next q lines contains one event. An event is either 1 a pa, where a is a city () and pa is the new number of potential passengers (), or 2 a, where a is a hub city. At least one event is of the second type.
Output
For each event of the second type, print the current influence of the given hub city on its own line, in the order the events appear.