CF938G.Shortest Path Queries

普及/提高-

通过率:0%

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:

  • 11 xx yy dd — add an edge connecting vertex xx to vertex yy with weight dd . It is guaranteed that there is no edge connecting xx to yy before this query;
  • 22 xx yy — remove an edge connecting vertex xx to vertex yy . It is guaranteed that there was such edge in the graph, and the graph stays connected after this query;
  • 33 xx yy — calculate the length of the shortest path (possibly non-simple) from vertex xx to vertex yy .

Print the answers for all queries of type 33 .

输入格式

The first line contains two numbers nn and mm ( 1<=n,m<=2000001<=n,m<=200000 ) — the number of vertices and the number of edges in the graph, respectively.

Then mm lines follow denoting the edges of the graph. Each line contains three integers xx , yy and dd ( 1<=x<y<=n1<=x<y<=n , 0<=d<=23010<=d<=2^{30}-1 ). Each pair (x,y)(x,y) is listed at most once. The initial graph is connected.

Then one line follows, containing an integer qq ( 1<=q<=2000001<=q<=200000 ) — the number of queries you have to process.

Then qq lines follow, denoting queries in the following form:

  • 11 xx yy dd ( 1<=x<y<=n1<=x<y<=n , 0<=d<=23010<=d<=2^{30}-1 ) — add an edge connecting vertex xx to vertex yy with weight dd . It is guaranteed that there is no edge connecting xx to yy before this query;
  • 22 xx yy ( 1<=x<y<=n1<=x<y<=n ) — remove an edge connecting vertex xx to vertex yy . It is guaranteed that there was such edge in the graph, and the graph stays connected after this query;
  • 33 xx yy ( 1<=x<y<=n1<=x<y<=n ) — calculate the length of the shortest path (possibly non-simple) from vertex xx to vertex yy .

It is guaranteed that at least one query has type 33 .

输出格式

Print the answers for all queries of type 33 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
    
首页