CF938G.Shortest Path Queries
省选/NOI-
通过率:0%
时间限制:3.50s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an undirected connected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times).
There are three types of queries you have to process:
- 1 x y d — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query;
- 2 x y — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query;
- 3 x y — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y.
Print the answers for all queries of type 3.
给你一个带权无向连通图。某条顶点间路径的“长度”定义为该路径上所有边的权重的按位异或(bitwise xor)值(若某条边被经过多次,则它在按位异或运算中也参与相应次数)。
你需要处理三种类型的查询:
1 x y d— 添加一条连接顶点x与y、权重为d的边。保证执行该查询前图中不存在连接x与y的边;2 x y— 删除连接顶点x与y的边。保证图中存在这样一条边,且删除后图仍保持连通;3 x y— 计算从顶点x到顶点y的最短路径(可能不是简单路径)的长度。
请输出所有类型为 3 的查询的答案。
输入格式
The first line contains two numbers n and m (1 ≤ n, m ≤ 200000) — the number of vertices and the number of edges in the graph, respectively.
Then m lines follow denoting the edges of the graph. Each line contains three integers x, y and d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1). Each pair (x, y) is listed at most once. The initial graph is connected.
Then one line follows, containing an integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.
Then q lines follow, denoting queries in the following form:
- 1 x y d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1) — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query;
- 2 x y (1 ≤ x < y ≤ n) — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query;
- 3 x y (1 ≤ x < y ≤ n) — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y.
It is guaranteed that at least one query has type 3.
第一行包含两个整数 n 和 m(1≤n,m≤200000),分别表示图中顶点的数量和边的数量。
接下来 m 行,每行描述图中的一条边。每行包含三个整数 x、y 和 d(1≤x<y≤n,0≤d≤230−1)。每对 (x,y) 至多出现一次。初始图是连通的。
随后一行包含一个整数 q(1≤q≤200000),表示你需要处理的查询数量。
接下来 q 行,每行表示一个查询,格式如下:
1 x y d(1≤x<y≤n,0≤d≤230−1)—— 添加一条连接顶点 x 与顶点 y、权值为 d 的边。保证在本次查询之前,x 与 y 之间没有边;2 x y(1≤x<y≤n)—— 删除连接顶点 x 与顶点 y 的边。保证图中原本存在该边,且删除后图仍保持连通;3 x y(1≤x<y≤n)—— 计算从顶点 x 到顶点 y 的最短路径长度(路径允许非简单,即允许重复经过顶点或边)。
保证至少有一个查询的类型为 3。
输出格式
Print the answers for all queries of type 3 in the order they appear in input.
按输入中出现的顺序输出所有类型为 3 的查询的答案。
输入输出样例
输入#1
5 5 1 2 3 2 3 4 3 4 5 4 5 6 1 5 1 5 3 1 5 1 1 3 1 3 1 5 2 1 5 3 1 5
输出#1
1 1 2
输入解题思路,AI测评打分。不知道怎么写?