This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 1000002
using namespace std;
int n,m,p,x,y,dp[MAX],cnt[MAX],mrc[MAX];
/// dp[nod] = in ce nod trebuie sa merg
/// cnt[nod] = cate drumuri sunt
vector<int> v[MAX];
void dfs(int nod){
if(nod == n){
dp[nod] = 1;
cnt[nod] = 1;
if(nod == mrc[p-dp[nod]+1]){
dp[nod]++;
}
}else{
for(int vecin: v[nod]){
if(dp[vecin] == 0){
dfs(vecin);
}
if(dp[vecin] > dp[nod]){
dp[nod] = dp[vecin];
cnt[nod] = cnt[vecin];
}else if(dp[vecin] == dp[nod]){
cnt[nod] += cnt[vecin];
}
}
if(nod == mrc[p-dp[nod]+1]){
dp[nod]++;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> p;
for(int i = 1; i <= p; i++){
cin >> mrc[i];
}
for(int i = 1; i <= m; i++){
cin >> x >> y;
v[x].push_back(y);
}
dfs(1);
cout << cnt[1];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |