比赛 2024暑假C班集训A 评测结果 AAAAAAAAAA
题目名称 轮子的旋转 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.033 s
代码语言 C++ 内存使用 3.54 MiB
提交时间 2024-07-10 08:28:16
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5+10;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}


int n;
struct made{
    int ver,nx,ed;
}e[N<<1];
int hd[N],tot;
void link(int x,int y,int z){e[++tot] = {y,hd[x],z},hd[x] = tot;}

int d[N];
void dfs(int x){
    for(int i = hd[x];i;i = e[i].nx){
        int y = e[i].ver,z = e[i].ed;
        d[y] = d[x] ^ z;
        dfs(y);
    }
}

int main(){
    freopen("rotation.in","r",stdin);
    freopen("rotation.out","w",stdout);
    n = read();
    for(int i = 1;i < n;i++){
        int x = read(),y = read(),z = read();
        link(x,y,z);
    }
    dfs(1);
    printf("%d\n",d[n]);
    
    
    return 0;
    
}