# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
301249 | marius7122 | Shell (info1cup18_shell) | C++14 | 1056 ms | 41240 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
const int MOD = 1e9 + 7;
vector<int> g[N], topOrd;
int n, m, p;
int ord[N], topOrdIndex[N], dp[N];
bool viz[N];
void topSort(int node)
{
viz[node] = true;
for(int y : g[node])
if(!viz[y])
topSort(y);
topOrd.push_back(node);
}
int main()
{
cin >> n >> m >> p;
for(int i = 0; i < p; i++)
cin >> ord[i];
ord[p] = n;
for(int i = 0; i < m; i++)
{
int x, y; cin >> x >> y;
g[x].push_back(y);
}
topOrd.reserve(n + 5);
for(int i = p-1; i >= 0; i--)
if(!viz[ord[i]])
topSort(ord[i]);
for(int i = 1; i <= n; i++)
if(!viz[i])
topSort(i);
reverse(topOrd.begin(), topOrd.end());
// for(int i : topOrd)
// cout << i << ' ';
// cout << '\n';
for(int i = 0; i < topOrd.size(); i++)
topOrdIndex[topOrd[i]] = i;
dp[1] = 1;
int nextStop = 0;
for(int node : topOrd)
{
if(node == ord[nextStop])
{
if(ord[nextStop] == n)
break;
nextStop++;
}
for(int y : g[node])
if(topOrdIndex[y] <= topOrdIndex[ord[nextStop]])
{
dp[y] += dp[node];
if(dp[y] >= MOD)
dp[y] -= MOD;
}
}
// for(int i = 1; i <= n; i++)
// cout << dp[i] << ' ';
cout << dp[n] << '\n';
return 0;
}
컴파일 시 표준 에러 (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... |