比赛 |
2024暑期C班集训3 |
评测结果 |
AAAAAAAAAAAAAAEWEEEE |
题目名称 |
不是一道路径查询问题 |
最终得分 |
70 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
1.567 s |
代码语言 |
C++ |
内存使用 |
14.44 MiB |
提交时间 |
2024-07-03 11:14:39 |
显示代码纯文本
#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,m,q;ll V;
struct made{
int ver,nx;ll ed;
}e[N<<1];
int hd[N],tot;
void add(int x,int y,ll z){e[++tot] = {y,hd[x],z},hd[x] = tot;}
bool v[N];
ll s[70],cnt;
struct DSU{
int fa[N];
void build(){for(int i = 1;i <= n;i++)fa[i] = i;}
int find(int x){
if(x == fa[x])return x;
return fa[x] = find(fa[x]);
}
void merge(int x,int y){
x = find(x),y = find(y);
if(x == y)return;
fa[y] = x;
}
}d[70];
void dfs(int x,int now){
v[x] = 1;
for(int i = hd[x];i;i = e[i].nx){
int y = e[i].ver;
if((e[i].ed & s[now]) == s[now])d[now].merge(x,y);
if(v[y])continue;
dfs(y,now);
}
}
int main(){
freopen("Paths.in","r",stdin);
freopen("Paths.out","w",stdout);
n = read(),m = read(),q = read(),V = read();
s[++cnt] = V;
for(int i = 0;i <= 60;i++)
if((V & (1ll<<i)) == 0)s[++cnt] = (V - (V & ((1ll<<i)-1))) | (1ll<<i);
for(int i = 1;i <= m;i++){
int x = read(),y = read();ll z = read();
add(x,y,z),add(y,x,z);
}
for(int i = 1;i <= cnt;i++){
memset(v,0,sizeof v);
d[i].build();
for(int j = 1;j <= n;j++)
if(!v[j])dfs(j,i);
}
for(int i = 1;i <= q;i++){
int u = read(),v = read();
bool f = 0;
for(int j = 1;j <= cnt;j++)
if(d[j].find(u) == d[j].find(v)){f = 1;break;}
if(f)printf("Yes\n");
else printf("No\n");
}
return cerr<<clock()<<"ms"<<endl,0;
}