QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410734#6679. Not Another Path Query Problemyi_y#TL 1ms5648kbC++111.6kb2024-05-14 13:16:282024-05-14 13:16:28

Judging History

This is the latest submission verdict.

  • [2024-05-14 13:16:28]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 5648kb
  • [2024-05-14 13:16:28]
  • Submitted

answer

#include<iostream>
using namespace std;

#define ll long long
ll n,m,q,v,a,b,c,cnt,head[100010],par[100010];
bool vis[100010];
struct e
{
    ll to,next,w;
}edge[1000010];

void addedge(int x,int y,int z)
{
    edge[++cnt].to = y;
    edge[cnt].w = z;
    edge[cnt].next = head[x];
    head[x] = cnt;
}

ll find(ll x)
{
    if(x!=par[x])
        par[x] = find(par[x]);
    return par[x];
}

void unionn(ll x,ll y)
{
    int i = find(x);
    int j = find(y);
    if(i!=j)
        par[i] = j;
}

bool dfs(ll x,ll y)
{
    if(y == b)
    {
        if(x>=v)
        {
            puts("Yes");
            return true;
        }
        else
        {
            return false;
        }
    }
    for(int i=head[y];i;i=edge[i].next)
    {
        if(!vis[edge[i].to])
        {
            vis[edge[i].to] = 1;
            bool k = dfs(edge[i].w&x,edge[i].to);
            vis[edge[i].to] = 0;
            if(k)
                return true;
        }
    }
    return false;
}

void solve()
{
    cin>>a>>b;
    if(find(a)!=find(b)){
        puts("No");return;
    }

    vis[a] = 1;
    for(int i=head[a];i;i=edge[i].next)
    {
        vis[edge[i].to] = 1;
        bool k = dfs(edge[i].w,edge[i].to);
        vis[edge[i].to] = 0;
        if(k)
            return;
    }
    puts("No");
    return;
}

int main()
{
    cin>>n>>m>>q>>v;
    for(int i=1;i<=n;i++)
        par[i] = i;
    while(m--)
    {
        cin>>a>>b>>c;
        addedge(a,b,c);
        addedge(b,a,c);
        unionn(a,b);
    }
    while(q--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5648kb

input:

9 8 4 5
1 2 8
1 3 7
2 4 1
3 4 14
2 5 9
4 5 7
5 6 6
3 7 15
1 6
2 7
7 6
1 8

output:

Yes
No
Yes
No

result:

ok 4 token(s): yes count is 2, no count is 2

Test #2:

score: 0
Accepted
time: 1ms
memory: 5592kb

input:

3 4 1 4
1 2 3
1 2 5
2 3 2
2 3 6
1 3

output:

Yes

result:

ok YES

Test #3:

score: -100
Time Limit Exceeded

input:

100 2000 50000 0
32 52 69658009083393280
26 38 868250171554967916
87 32 743903879320440454
22 15 19782587273744714
57 98 845866434191429143
42 95 1145336983294966993
67 40 1036117659380117375
46 24 265457274847122243
63 44 438254608190938148
28 23 992625102587165494
57 87 558124114385470345
6 17 535...

output:

Yes

result: