P2420 让我们异或吧

链接Miku

dfs就行了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int head[100001];
int p;
int n;
int m;
int x,y,z;
int dis[100001];
struct e{
    int to;
    int ne;
    int v;
}ed[200001];
void add(int f,int t,int v){
    p++;
    ed[p].ne=head[f];
    ed[p].to=t;
    ed[p].v=v;
    head[f]=p;
    return ;
}
void dfs(int now,int f){
    for(int i=head[now];i;i=ed[i].ne){
        if(ed[i].to==f) continue;
         dis[ed[i].to]=dis[now]^ed[i].v;
         dfs(ed[i].to,now);
    } 
    return ;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;++i){
        scanf("%d%d%d",&x,&y,&z);
        add(x,y,z);
        add(y,x,z);
    }
    scanf("%d",&m);
    dfs(1,1);
    for(int i=1;i<=m;++i){
        scanf("%d%d",&x,&y);
        x=dis[x]^dis[y];
        cout<< x <<endl;
    }
    return 0; 
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇