Mod Graph

시간 제한1초메모리 제한2048 MB

요약
정점을 방문할 때마다 값이 b_v로 나눈 나머지로 1씩 증가하는 연결 그래프에서, s에서 시작하는 보행으로 모든 값을 0으로 만들 수 있는지 판정한다.
난이도

어려움10점 중 9점

유형
그래프, 정수론, 수학, DFS
정답자
아직 제출이 없습니다

문제

You are given an undirected, connected graph with nn vertices. Every vertex vv has a counter that operates modulo b_vb\_v. The initial state of that counter is a_va\_v. Every time you visit that vertex, it is increased by one (i.e. a_v←(a_v+1) mod b_va\_v \leftarrow (a\_v + 1) \bmod b\_v).

You have to process qq queries of the following two types:

  • "1 ss": Suppose that you start at vertex ss, you have to answer whether it is possible to make a_v=0a\_v = 0 for all vv. You are allowed to take an arbitrary walk through GG, i.e. you can use edges and vertices multiple times. Note that starting the walk at ss already counts as visiting ss, i.e. its counter is increased by one initially.
  • "2 vv xx": Update a_v←xa\_v \leftarrow x.

입력

The first line contains three integers nn, mm, and qq (1≤n,q≤5⋅1041 \leq n,q \leq 5 \cdot 10^4, 0≤m≤1050 \leq m \leq 10^5) --- the number of vertices, edges, and queries, respectively.

The second line contains nn integers a_1,…,a_na\_1, \ldots, a\_n.

The third line contains nn integers b_1,…,b_nb\_1, \ldots, b\_n (0≤a_v<b_v≤1090 \leq a\_v < b\_v \leq 10^9).

The following mm lines contain the edges of the graph. Each of those mm lines contains two integers uu and vv (1≤u,v≤n1 \leq u, v \leq n, u≠vu \neq v) describing an edge connecting vertices uu and vv. The given graph is connected.

Finally, there are qq lines describing the queries. They can be in the two formats described above, i.e.

  • "1 ss": (1≤s≤n1 \leq s \leq n)
  • "2 vv xx": (1≤v≤n1 \leq v \leq n, 0≤x<b_v0 \leq x < b\_v)

출력

For each query of type 1, output YES in one line if it is possible to make a_v=0a\_v = 0 for all vv and NO otherwise.

힌트

In the first query, we start at vertex 11 with counter states \[1,0]\[1, 0].

We move along the walk 1→2→1→2→1→21 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 1 \rightarrow 2.

The counter states change as follows: \[1,0]→\[1,1]→\[2,1]→\[2,2]→\[0,2]→\[0,0]\[1, 0] \rightarrow \[1, 1] \rightarrow \[2, 1] \rightarrow \[2, 2] \rightarrow \[0, 2] \rightarrow \[0, 0].

예제1

  1. 예제 1

    입력
    2 1 4
    0 0
    3 3
    1 2
    1 1
    2 1 1
    1 1
    1 2
    
    예상 출력
    YES
    NO
    YES