No.3508 OR Mapping
タグ : / 解いたユーザー数 40
作問者 :
Solalyth
Problem Statement
You are given a simple directed graph with $N$ vertices and $M$ edges, whose vertices are numbered from $1$ to $N$. The $i$-th edge is a directed edge from vertex $u_i$ to vertex $v_i$.
Each vertex can hold an integer between $0$ and $2^{K} - 1$, inclusive, and initially $0$ is written on every vertex.
There is $1$ piece placed on vertex $1$. There is also a variable $T$, initially $T = 0$.
You may repeat the following operation as many times as you like.
- Let vertex $i$ be the vertex where the piece is currently placed. Choose a vertex $j$ such that there is an edge from vertex $i$ to vertex $j$, and move the piece to vertex $j$. Then, after adding $1$ to $T$, let $x$ be the value written on vertex $j$, and rewrite $x$ to $x\ \text{OR}\ (T \bmod 2^{K})$. Here, $A\ \text{OR}\ B$ denotes the bitwise OR of $A$ and $B$.
Your goal is to make the value written on every vertex equal to $2^K-1$. Determine whether this is possible.
Constraints
- $1 \le N \le 5 \times 10^5$
- $0 \le M \le \min \left( N(N-1) ,5 \times 10^5 \right)$
- $1 \le K \le 51$
- $1\le u_i , v_i \le N$
- $u_i \ne v_i$
- $i \ne j \Rightarrow (u_i,v_i) \ne (u_j,v_j)$
- All input values are integers.
Input
The input is given from Standard Input in the following format.$N$ $M$ $K$ $u_1$ $v_1$ $u_2$ $v_2$ $\vdots$ $u_M$ $v_M$
Output
Print Yes if it is possible, and No otherwise, on a single line.
Sample
Sample 1
Input
3 3 2 1 2 2 3 3 1
Output
Yes
Let $A$ be the sequence of numbers written on the vertices, in the order of vertices $1,2,3$.
- Move the piece from vertex 1 to vertex 2. $A = (0, 1, 0)$ results.
- Move the piece from vertex 2 to vertex 3. $A = (0, 1, 2)$ results.
- Move the piece from vertex 3 to vertex 1. $A = (3, 1, 2)$ results.
- Move the piece from vertex 1 to vertex 2. $A = (3, 1, 2)$ results.
- Move the piece from vertex 2 to vertex 3. $A = (3, 1, 3)$ results.
- Move the piece from vertex 3 to vertex 1. $A = (3, 1, 3)$ results.
- Move the piece from vertex 1 to vertex 2. $A = (3, 3, 3)$ results.
By moving in this way, the values written on all vertices can be made 3, so the answer is Yes.
Sample 2
Input
3 3 2 1 2 2 3 1 3
Output
No
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。