Live2D

# 【LGOJ5651】基础最短路练习题

"保证G中不存在简单环使得边权异或和不为0"

#include<bits/stdc++.h>
#define ll long long
#define N 500005
using namespace std;

int n,m,q,u,v;
ll w;

struct Edge
{
int next,to;
ll dis;
}edge[N<<1];
int cnt=0,head[N];

inline void add_edge(int from,int to,ll dis)
{
edge[++cnt].next=head[from];
edge[cnt].to=to;
edge[cnt].dis=dis;
head[from]=cnt;
}

int dep[N];
ll dis[N];
void dfs(int u,int fa)
{
for(register int i=head[u];i;i=edge[i].next)
{
int v=edge[i].to;
if(v==fa) continue;
if(dep[v]!=0x3f3f3f3f) continue;
dep[v]=dep[u]+1;
dis[v]=dis[u]^edge[i].dis;
dfs(v,u);
}
}

template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main()
{
read(n);read(m);read(q);
for(register int i=1;i<=m;++i)
{
read(u);read(v);read(w);
add_edge(u,v,w);
add_edge(v,u,w);
}
memset(dep,0x3f,sizeof(dep));
dep[1]=0;
dfs(1,0);
while(q--)
{
read(u);read(v);
printf("%lld\n",dis[u]^dis[v]);
}
return 0;
}

$$\text{这里是tqr，联系我请加QQ735748368}$$
posted @ 2019-11-14 07:27  tqr06  阅读(132)  评论(0编辑  收藏  举报