Logo
(追記) (追記ここまで)

19501번 - XOR Tree 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB455522.727%

문제

There is an undirected graph $G$ with $n$ vertices. It has an interesting property: if we treat multiple edges as one, the graph $G$ will become a tree. Alice and Bob invented the following game:

  • At the beginning, Alice and Bob choose two vertices $S$ and $T,ドル $S \ne T$.
  • There is another graph $H$ with $n$ vertices and, initially, no edges.
  • On every turn, the current player chooses any edge $u-v$ in graph $G,ドル deletes it and changes the state of edge $u-v$ in graph $H$: if there was no such edge in graph $H,ドル it appears, and if there was such an edge, it disappears.
  • Alice wins if there exists a moment of time when there is a path between $S$ and $T$ in graph $H$.
  • If there is no edge in graph $G$ and Alice hasn't won yet, Bob wins.
  • Players take turns, Alice moves first.

Children like the game very much so they have played it $q$ times. Now they are wondering who would win in each game if they were playing optimally. Help them find it out!

입력

The first line of input contains two integers $n$ and $q$: the number of vertices in graph $G$ and the number of games played by Alice and Bob (2ドル \le n \le 10^5,ドル 1ドル \le q \le 10^5$).

The next $n-1$ lines contain the description of graph $G$. Each line consists of three integers $a,ドル $b$ and $c$ (1ドル \le a, b \le n,ドル 1ドル \le c \le 10^9$) which means there are exactly $c$ edges between vertices $a$ and $b$. It is guaranteed that, if we change all $c$ to 1ドル,ドル the graph $G$ will become a tree with $n$ vertices.

The next $q$ lines describe the games. Each of these lines contains two integers $S$ and $T$: the parameters of the game (1ドル \le S, T \le n,ドル $S \ne T$).

출력

For each game, print 1 if Alice wins, and print 2 otherwise. Separate the answers with line breaks.

제한

예제 입력 1

6 5
1 2 3
1 3 2
2 4 1
2 5 2
3 6 2
1 4
5 4
5 6
2 6
4 6

예제 출력 1

1
1
2
2
2

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2016 > Day 7: Ural FU Dandelion Contest G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /