F - Two Faced Edges Editorial /

Time Limit: 5 sec / Memory Limit: 256 MB

配点 : 11001100

問題文

NN 頂点 MM 辺の単純な有向グラフが与えられます。 頂点には 1,2,...,N1, 2, ..., N の番号が,辺には 1,2,...,M1, 2, ..., M の番号が付いています。 辺 ii は頂点 aia_i から頂点 bib_i へ伸びています。

それぞれの辺について,もしその辺を反転させたらグラフの強連結成分の個数が変わるかどうかを求めてください。

なお,辺 ii を反転させるとは,グラフから辺 ii を削除し, 新たに頂点 bib_i から頂点 aia_i へ伸びる辺を追加する操作を意味します。

制約

  • 2N10002 \leq N \leq 1000
  • 1M200,0001 \leq M \leq 200,000
  • 1ai,biN1 \leq a_i, b_i \leq N
  • aibia_i \neq b_i
  • iji \neq j ならば aiaja_i \neq a_j または bibjb_i \neq b_j

入力

入力は以下の形式で標準入力から与えられる。

NN MM
a1a_1 b1b_1
a2a_2 b2b_2
::
aMa_M bMb_M

出力

MM 行出力せよ。ii 行目には,辺 ii を反転させたらグラフの強連結成分の個数が変わる場合 diff,変わらない場合 same と出力せよ。


入力例 1Copy

Copy
3 3
1 2
1 3
2 3

出力例 1Copy

Copy
same
diff
same

辺を反転させない場合強連結成分の個数は 33 個ですが,辺 22 を反転させると強連結成分の個数は 11 個になります。


入力例 2Copy

Copy
2 2
1 2
2 1

出力例 2Copy

Copy
diff
diff

辺を反転させた結果,グラフに多重辺が生じる場合もあります。


入力例 3Copy

Copy
5 9
3 2
3 1
4 1
4 2
3 5
5 3
3 4
1 2
2 5

出力例 3Copy

Copy
same
same
same
same
same
diff
diff
diff
diff

Score : 11001100 points

Problem Statement

You are given a directed graph with NN vertices and MM edges. The vertices are numbered 1,2,...,N1, 2, ..., N, and the edges are numbered 1,2,...,M1, 2, ..., M. Edge ii points from Vertex aia_i to Vertex bib_i.

For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph.

Here, the reversion of Edge ii means deleting Edge ii and then adding a new edge that points from Vertex bib_i to Vertex aia_i.

Constraints

  • 2N10002 \leq N \leq 1000
  • 1M200,0001 \leq M \leq 200,000
  • 1ai,biN1 \leq a_i, b_i \leq N
  • aibia_i \neq b_i
  • If iji \neq j, then aiaja_i \neq a_j or bibjb_i \neq b_j.

Input

Input is given from Standard Input in the following format:

NN MM
a1a_1 b1b_1
a2a_2 b2b_2
::
aMa_M bMb_M

Output

Print MM lines. In the ii-th line, if the reversion of Edge ii would change the number of the strongly connected components in the graph, print diff; if it would not, print same.


Sample Input 1Copy

Copy
3 3
1 2
1 3
2 3

Sample Output 1Copy

Copy
same
diff
same

The number of the strongly connected components is 33 without reversion of edges, but it will become 11 if Edge 22 is reversed.


Sample Input 2Copy

Copy
2 2
1 2
2 1

Sample Output 2Copy

Copy
diff
diff

Reversion of an edge may result in multiple edges in the graph.


Sample Input 3Copy

Copy
5 9
3 2
3 1
4 1
4 2
3 5
5 3
3 4
1 2
2 5

Sample Output 3Copy

Copy
same
same
same
same
same
diff
diff
diff
diff


2025-05-11 (Sun)
14:59:46 +00:00