QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#556018 | #8517. Interesting Paths | CCF_NOI# | WA | 2ms | 8204kb | C++20 | 690b | 2024-09-10 14:06:32 | 2024-09-10 14:06:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,g[N],f[N];
vector<int>e[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);
++g[u];
}
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);
}
}
f[1]=1;
for(int i=1;i<=n;++i)if(g[i]||i==n){
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: 2ms
memory: 8200kb
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: 2ms
memory: 7896kb
input:
5 3 1 3 2 3 2 5
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5788kb
input:
2 0
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 2ms
memory: 8200kb
input:
2 1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 8204kb
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:
3
result:
wrong answer 1st numbers differ - expected: '0', found: '3'