QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#797780 | #9810. Obliviate, Then Reincarnate | AiriS# | WA | 509ms | 56996kb | C++14 | 2.6kb | 2024-12-03 18:13:27 | 2024-12-03 18:13:27 |
Judging History
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=1000003;
int n,m,q;
struct Edge{
int nxt,to;
ll w;
}e[N];
int U[N],V[N];
ll W[N];
struct Node{
int x,y;
bool operator <(const Node A)const{
if(x!=A.x) return x<A.x;
return y<A.y;
}
};
map<Node,ll> ed;
int cnt,head[N];
int idx,col,dfn[N],low[N],scc[N];
ll dis[N];
int top,s[N];
int in[N];
bool v[N],flag[N];
void add(int u,int v,ll w){
e[++cnt]=(Edge){head[u],v,w};
head[u]=cnt;
}
void tarjan(int x,ll val){
dfn[x]=low[x]=++idx;
s[++top]=x;
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++;
ll lst=0;
do{
dis[s[top]]=lst;
if(s[top]!=x) lst-=ed[(Node){s[top-1],s[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]=((U[i]+y)%n+n)%n;
W[i]=y;
add(U[i],V[i],W[i]);
ed[(Node){U[i],V[i]}]=W[i];
}
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: 20132kb
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: 11992kb
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: 4028kb
input:
1 1 1 0 1000000000 -1000000000
output:
Yes
result:
ok "Yes"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3808kb
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: 509ms
memory: 56996kb
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'