포럼
문제 ICPC00331

K. Xortest Path

설명

Rules and regulations about mileage reimbursement for employees are very clear: the employee should be refunded an amount of money proportional to the shortest distance between their home and office. This causes your X-mas Ornaments Retailer a great deal of pain: every year more and more money is spent on reimbursement and this means your companies have less profit! This obviously has to be stopped and so you delve deep into the regulations about reimbursement, hoping to find a loophole so you do not have to give as much money to your employees.

However, the rules seem pretty strict. As long as the employees keep track of the distances they have travelled, you are forced to reimburse them. Suddenly you have a flash of inspiration: nowhere does it say that you have to use the Euclidean distances! You start working on more subtle distance functions and now you have a first prototype: XOR distance. The length of a path is defined as the XOR of the lengths of the edges on the path (as opposed to the sum). The distance between two locations is defined as the length of the shortest path between them. You hope that the authorities will not notice that this does not define a metric, but before you send them your proposal you want to experiment with this distance first.

You cook up a simple connected weighted undirected graph with this distance function, and you ask yourself \(q\) questions about this graph, each asking about the shortest XOR distance between two nodes.

제약
입력 형식

The input consists of:
- One line containing three integers \(n\) (\(2 \leq n \leq 10^4\)), \(m\) (\(n-1 \leq m \leq 10^5\)), and \(q\) (\({1 \leq q \leq 10^5}\)), the number of nodes, edges, and questions respectively.
- \(m\) lines describing an edge. Each line consists of three integers \(x\), \(y\), \(w\) (\(1 \leq x,y \leq n\), \(x\neq y\) and \(0 \leq w \leq 10^{18}\)), indicating that there is an undirected edge of length \(w\) between nodes \(x\) and \(y\).
- \(q\) lines describing a question. Each line consists of two integers \(a\), \(b\) (\(1 \leq a,b \leq n\)) asking for the shortest distance between nodes \(a\) and \(b\).

There is at most one edge between any pair of distinct nodes and every node can be reached from any other node.

출력 형식

For every question, output one line containing the shortest distance between nodes \(a\) and \(b\).

예제 1
입력
3 3 3
1 2 2
1 3 2
2 3 3
1 2
1 3
2 3
출력
1
1
0
예제 2
입력
7 10 5
1 2 45
2 3 11
2 4 46
3 4 28
3 5 59
3 6 12
3 7 3
4 5 11
5 6 23
6 7 20
1 4
2 6
3 5
1 7
5 5
출력
1
5
0
5
0
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2020

평가 및 의견

K. Xortest Path

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

K. Xortest Path

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8