QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#788712#9810. Obliviate, Then ReincarnatecrychicWA 215ms26124kbC++202.4kb2024-11-27 18:00:572024-11-27 18:00:58

Judging History

This is the latest submission verdict.

  • [2024-11-27 18:00:58]
  • Judged
  • Verdict: WA
  • Time: 215ms
  • Memory: 26124kb
  • [2024-11-27 18:00:57]
  • Submitted

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int maxn=5e5+5;
vector<pii>e[maxn];
int dfn[maxn],low[maxn],cnt;
int inst[maxn],scc[maxn],sc;
int fl[maxn],ans[maxn],ok[maxn];
vector<int>ins[maxn],stk;
void dfs(int x){
	dfn[x]=low[x]=++cnt;
	inst[x]=1;
	stk.push_back(x);
	for(auto t:e[x]){
		int u=t.first;
		if(!dfn[u]){
			dfs(u);
			low[x]=min(low[x],low[u]);
		}
		else if(inst[u])low[x]=min(low[x],dfn[u]);
	}
	if(low[x]==dfn[x]){
		sc++;
		while(1){
			int u=stk.back();
			inst[u]=0;
			scc[u]=sc;
			ins[sc].push_back(u);
			stk.pop_back();
			if(u==x)break;
		}
	}
}
ll dis[maxn];
int vis[maxn],T;
void dfs2(int x){
    if(ok[T]) return ;
	vis[x]=1;
	for(auto t:e[x]){
		int u=t.first,w=t.second;
		if(scc[u]!=scc[x])continue;
		if(vis[u]){
			if(dis[u]!=dis[x]+w)fl[T]=1,ok[T]=1;
			continue;
		}
		dis[u]=dis[x]+w;
		dfs2(u);
	}
}
void solve(){
	int n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=m;i++){
		// int u,v,w;
		// cin>>u>>w;
		// u=(u%n+n)%n+1;
		// v=((u+w)%n+n)%n+1;
        int a, b;
        cin >> a >> b;
        int w = b;
        int u = (a % n + n) % n, v = ((a + b) % n + n) % n;       
        u ++ ;
        v ++ ; 
		e[u].push_back({v,w});
		// cout<<u<<" "<<v<<" "<<w<<"\n";
	}
	for(int i=1;i<=n;i++){
		if(!dfn[i]){
			dfs(i);
		}
	}
	for(int i=1;i<=sc;i++){
		T=i;
		dfs2(ins[i][0]);
		if(fl[i]){
			for(auto u:ins[i]){
				ans[u]=1;
			}
		}
	}

    vector<int> din(n + 1);
    vector<vector<int> > edge_scc(sc + 1);
    for(int i = 1; i <= n; i ++ ) {
        for(auto [v, w] : e[i]) {
            int a = scc[i], b = scc[v];
            if(a != b) {
                edge_scc[b].push_back(a);
                din[a] ++ ;
            }
        }
    }
 
    queue<pii> q1;
    for(int i = 1; i <= sc; i ++ ) {
        if(!din[i]) {
            q1.push({i, ok[i]});
        }
    }
    while(q1.size()) {
        auto [u, staut] = q1.front();
        q1.pop();
        for(auto v : edge_scc[u]) {
            ok[v] |= staut;
            if(-- din[v] == 0) q1.push({v, ok[v]});
        }
    }
	for(int i=1;i<=q;i++){ 
		int x;
		cin>>x;
		x=(x%n+n)%n+1;
		if(ok[x])cout<<"Yes\n";
		else cout<<"No\n";
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	// cin>>t;
	while(t--)solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7688kb

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: 5936kb

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: 3ms
memory: 10028kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

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

input:

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

output:

No
No
No

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 171ms
memory: 18776kb

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:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 500000 tokens

Test #6:

score: -100
Wrong Answer
time: 215ms
memory: 26124kb

input:

100848 500000 500000
720352587 361776806
231853504 -933882325
960971230 -83519300
-152772415 -631132247
842871215 -666621297
857194330 -754943024
-698506963 -705416545
-3551931 -927937446
628710320 -942247987
674921043 847145884
-325629529 475694308
-339363446 686789318
236702996 654762989
420412365...

output:

No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No...

result:

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