update
This commit is contained in:
parent
60a6fcaa0a
commit
ff4fd8c890
44
src/2/P2420.cpp
Normal file
44
src/2/P2420.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using ll = int64_t;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T input(){
|
||||||
|
T t;
|
||||||
|
std::cin>>t;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ll maxn = 100000;
|
||||||
|
const ll n = input<ll>();
|
||||||
|
std::vector<std::pair<ll, ll>> edg[maxn+5];
|
||||||
|
ll xo[maxn+5];
|
||||||
|
|
||||||
|
void dfs(ll f,ll now){
|
||||||
|
for(auto const& [v,w]:edg[now]){
|
||||||
|
if(v==f){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
xo[now]=xo[f]^w;
|
||||||
|
dfs(now,v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
for(ll i=1;i<n;i++){
|
||||||
|
static ll u,v,w;
|
||||||
|
std::cin>>u>>v>>w;
|
||||||
|
edg[u].emplace_back(v,w);
|
||||||
|
edg[v].emplace_back(u,w);
|
||||||
|
}
|
||||||
|
ll m=input<ll>();
|
||||||
|
dfs(0,1);
|
||||||
|
while(m--){
|
||||||
|
static ll u,v;
|
||||||
|
std::cin>>u>>v;
|
||||||
|
std::cout<<(xo[u]^xo[v])<<'\n';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user