QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#556021 | #8517. Interesting Paths | CCF_NOI# | WA | 3ms | 10212kb | C++20 | 911b | 2024-09-10 14:11:16 | 2024-09-10 14:11:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,g[N],h[N],f[N];
vector<int>e[N],to[N];
bool inq[N];
queue<int>q;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;++i){
int u,v;
scanf("%d%d",&u,&v);
e[v].push_back(u);
to[u].push_back(v);
++g[u];
++h[v];
}
for(int i=1;i<=n;++i)sort(e[i].begin(),e[i].end(),greater<int>());
for(int i=1;i<n;++i)if(g[i]==0)q.push(i);
while(!q.empty()){
int nw=q.front();
q.pop();
for(int i:e[nw]){
--g[i];
if(g[i]==0)q.push(i);
}
}
for(int i=2;i<=n;++i)if(h[i]==0)q.push(i);
while(!q.empty()){
int nw=q.front();
q.pop();
for(int i:to[nw]){
--h[i];
if(h[i]==0)q.push(i);
}
}
f[1]=1;
for(int i=2;i<=n;++i)if((g[i]||i==n)&&h[i]){
for(int j:e[i]){
if(!inq[j]){
inq[j]=1;
f[i]+=f[j];
}
else ++f[i];
}
}
printf("%d",f[n]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 10008kb
input:
5 7 1 3 3 5 1 2 2 3 3 4 4 5 2 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9952kb
input:
5 3 1 3 2 3 2 5
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 2ms
memory: 5784kb
input:
2 0
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 10212kb
input:
2 1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 3ms
memory: 9932kb
input:
10 20 2 8 5 8 4 8 3 10 3 7 2 7 2 5 1 7 6 9 6 10 2 4 5 9 2 10 3 9 7 8 4 10 3 6 2 3 5 7 6 8
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 9952kb
input:
10 30 8 9 1 5 3 6 4 6 4 7 6 9 3 5 5 6 3 8 1 4 3 4 7 8 2 4 4 5 1 8 6 10 2 10 9 10 1 2 8 10 2 7 2 8 2 5 7 9 2 6 4 8 1 7 1 6 7 10 4 9
output:
22
result:
wrong answer 1st numbers differ - expected: '19', found: '22'