# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
363893 | ogibogi2004 | Shell (info1cup18_shell) | C++14 | 610 ms | 45036 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e6+6;
const ll mod=1e9+7;
int n,m,p;
vector<int>g[MAXN];
vector<int>t;
bool vis[MAXN];
void dfs(int u)
{
vis[u]=1;
for(auto v:g[u])
{
if(vis[v]==0)
{
dfs(v);
}
}
t.push_back(u);
}
int a[MAXN];
int where[MAXN];
int w1[MAXN];
ll dp[MAXN];
int main()
{
cin>>n>>m>>p;
for(int i=1;i<=p;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
int x,y;
cin>>x>>y;
g[x].push_back(y);
}
for(int i=1;i<=n;i++)
{
if(vis[i]==0)
{
dfs(i);
}
}
reverse(t.begin(),t.end());
for(int i=0;i<t.size();i++)where[t[i]]=i;
for(int i=2;i<=p;i++)
{
if(where[i-1]>where[i])
{
cout<<"0\n";
return 0;
}
}
if(where[a[1]]<where[1])
{
cout<<"0\n";
return 0;
}
if(where[a[p]]>where[n])
{
cout<<"0\n";
return 0;
}
for(int i=0;i<MAXN;i++)w1[i]=n+3;
for(int j=where[a[1]]-1;j>=0;j--)w1[j]=where[a[1]];
for(int i=2;i<=p;i++)
{
for(int j=where[a[i]]-1;j>=where[a[i-1]];j--)
{
w1[j]=where[a[i]];
}
}
dp[1]=1;
for(int i=0;i<t.size();i++)
{
for(auto v:g[t[i]])
{
if(where[v]>w1[i])continue;
dp[v]+=dp[t[i]];
dp[v]%=mod;
}
}
cout<<dp[n]<<endl;
return 0;
}
/*
6 9 2
1 3
1 3
1 3
1 2
2 3
2 4
3 4
3 5
4 5
5 6
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |