A11601 | Shortest Path Queries
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
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<=2^{30}-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<=2^{30}-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$ .
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<=2^{30}-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<=2^{30}-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$ .
输出格式
Print the answers for all queries of type $3$ in the order they appear in input.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted