QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797760#9810. Obliviate, Then ReincarnateAiriS#WA 138ms20024kbC++142.4kb2024-12-03 17:40:532024-12-03 17:40:53

Judging History

This is the latest submission verdict.

  • [2024-12-03 17:40:53]
  • Judged
  • Verdict: WA
  • Time: 138ms
  • Memory: 20024kb
  • [2024-12-03 17:40:53]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>void read(T &x){
    x=0;char c=getchar();bool f=false;
    while(c<'0'||c>'9'){if(c=='-')f=true;c=getchar();}
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f) x=-x;
}
const int N=500003;
int n,m,q;
struct Edge{
    int nxt,to,w;
}e[N];
int U[N],V[N],W[N];
int cnt,head[N];
int idx,col,dfn[N],low[N],scc[N],dis[N];
int top,s[N],ed[N];
int in[N];
bool v[N],flag[N];
void add(int u,int v,int w){
    e[++cnt]=(Edge){head[u],v,w};
    head[u]=cnt;
}
void tarjan(int x,int val){
    dfn[x]=low[x]=++idx;
    s[++top]=x;
    ed[top]=val;
    v[x]=true;
    for(int i=head[x];i;i=e[i].nxt){
        int to=e[i].to;
        if(!dfn[to]){
            tarjan(to,e[i].w);
            low[x]=min(low[x],low[to]);
        }
        else if(v[to])
            low[x]=min(low[x],dfn[to]);
    }
    if(dfn[x]==low[x]){
        col++;
        int lst=0;
        do{
            dis[s[top]]=lst;
            lst-=ed[top];
            scc[s[top]]=col;
            v[s[top]]=false;
        }while(s[top--]!=x);
    }
}
void chk(int x){
    for(int i=head[x];i;i=e[i].nxt){
        int to=e[i].to;
        if(scc[x]==scc[to]&&dis[x]+e[i].w!=dis[to])
            flag[scc[x]]=true;
    }
}
void rebuild(){
    for(int i=0;i<n;i++)
        head[i]=0;
    cnt=0;
    for(int i=1;i<=m;i++){
        if(scc[U[i]]!=scc[V[i]]){
            add(scc[V[i]],scc[U[i]],W[i]);
            in[scc[U[i]]]++;
        }
    }
}
void topsort(){
    queue<int> q;
    for(int i=1;i<=col;i++)
        if(!in[i]) q.push(i);
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=head[x];i;i=e[i].nxt){
            int to=e[i].to;
            flag[to]|=flag[x];
            in[to]--;
            if(in[to]==0) q.push(to);
        }
    }
}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        U[i]=(x%n+n)%n;
        V[i]=((x+y)%n+n)%n;
        W[i]=y;
        add(U[i],V[i],y);
    }
    for(int i=0;i<n;i++)
        if(!dfn[i]) tarjan(i,0);
    for(int i=0;i<n;i++)
        chk(i);
    rebuild();
    topsort();
    while(q--){
        int x;
        scanf("%d",&x);
        x=(x%n+n)%n;
        if(flag[scc[x]]) puts("Yes");
        else puts("No");
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 20024kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
Yes
No

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 2ms
memory: 13896kb

input:

3 2 3
1 1
-1 0
1
2
3

output:

No
No
No

result:

ok 3 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 4000kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

3 2 3
0 1000000000
1 -1000000000
-1000000000
0
-1000000000

output:

No
No
No

result:

ok 3 tokens

Test #5:

score: -100
Wrong Answer
time: 138ms
memory: 19468kb

input:

50134 500000 500000
-154428638 -283522863
-186373509 -327130969
154999046 46750274
-933523447 349415487
-437683609 140099255
864996699 -262318199
811293034 -264299324
120273173 52410685
874944410 -52048424
445049930 -803690605
-138111276 -104634331
720288580 126597671
471164416 -348777147
-356502322...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

wrong answer 1st words differ - expected: 'No', found: 'Yes'