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

20639번 - Cactus 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB182220.000%

문제

A cactus graph is a connected undirected graph without self-loops and multiple edges in which each edge belongs to at most one simple cycle.

Given is a cactus graph $G$ with $N$ vertices, numbered from 1ドル$ to $N,ドル and $M$ edges. The $i$-th edge connects vertices $a_i$ and $b_i,ドル and its cost is $c_i$.

Let the cost of a simple path on graph $G$ be bitwise XOR of the costs of all the edges on that path.

Answer $Q$ queries of the form "$x_i$ $y_i$ $k_i$}': consider the costs of all simple paths connecting vertices $x_i$ and $y_i,ドル remove duplicate values, sort the values in ascending order, and take $k_i$-th element. If the number of these values is less than $k_i,ドル answer $-1$.

입력

The first line of the input contains two integers $N$ and $M$: the number of vertices and the number of edges in the graph (2ドル \le N \le 10^5,ドル $N-1 \le M \le 2 \cdot 10^5$).

Each of the next $M$ lines describes one edge and contains three integers $a_i,ドル $b_i$ and $c_i$ (1ドル \le a_i, b_i \le N,ドル $a_i \ne b_i,ドル 0ドル \le c_i < 2^{30}$).

Then follows a line containing an integer $Q$: the number of queries (1ドル \le q \le 2 \cdot 10^5$).

Each of the next $Q$ lines describes one query and contains three integers $x_i,ドル $y_i$ and $k_i$ (1ドル \le x_i, y_i \le N,ドル $x_i \ne y_i,ドル 1ドル \le k_i \le 2^{30}$).

It is guaranteed that the graph given in the input is a cactus graph.

출력

For each query, print one integer on a separate line: the answer to that query.

제한

예제 입력 1

4 4
1 2 2
1 3 8
2 3 0
1 4 6
4
2 1 1
1 2 2
4 1 1
4 3 2020

예제 출력 1

2
8
6
-1

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2020 > Day 5: JAG Summer+ Opening Contest N번

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

출처

대학교 대회

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

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