답안 #96015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96015 2019-02-05T08:14:10 Z alextodoran Shell (info1cup18_shell) C++14
30 / 100
306 ms 154488 KB
#include <bits/stdc++.h>

#define NM 3000002
#define ll long long

using namespace std;

const ll MOD = 1e9+7;

vector <int> ine[NM], oute[NM];

int n, m, p;

int v[NM];
bool spv[NM];

int g[NM];

queue <int> q;

int ord[NM];

int vo[NM];

bool fs (int a, int b)
{
    return ord[a] < ord[b];
}

ll dp[NM];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> p;
    for(int i = 1; i <= p; i++)
    {
        cin >> v[i];
        spv[v[i]] = 1;
    }
    for(int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        ine[v].push_back(u);
        oute[u].push_back(v);
        g[v]++;
    }
    for(int i = 1; i <= n; i++)
        if(g[i] == 0)
        {
            ord[i] = 1;
            q.push(i);
        }
    while(!q.empty())
    {
        auto f = q.front();
        q.pop();
        for(auto e : oute[f])
        {
            g[e]--;
            if(g[e] == 0)
            {
                ord[e] = ord[f] + 1;
                q.push(e);
            }
        }
    }
    for(int i = 2; i <= p; i++)
        if(ord[v[i]] < ord[v[i - 1]])
        {
            cout << "0\n";
            return 0;
        }
    for(int i = 1; i <= n; i++)
        vo[i] = i;
    sort(vo + 1, vo + n + 1, fs);
    int last = 1;
    dp[1] = 1;
    for(int i = 1; i <= n; i++)
        if(vo[i] != 1)
        {
            for(auto e : ine[vo[i]])
                if(ord[e] >= ord[last])
                {
                    dp[vo[i]] += dp[e];
                    if(dp[vo[i]] >= MOD)
                        dp[vo[i]] -= MOD;
                }
            if(spv[vo[i]])
                last = vo[i];
        }
    cout << dp[n] << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 141432 KB Output is correct
2 Correct 126 ms 141216 KB Output is correct
3 Correct 128 ms 141432 KB Output is correct
4 Correct 126 ms 141428 KB Output is correct
5 Correct 125 ms 141288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 141432 KB Output is correct
2 Correct 126 ms 141216 KB Output is correct
3 Correct 128 ms 141432 KB Output is correct
4 Correct 126 ms 141428 KB Output is correct
5 Correct 125 ms 141288 KB Output is correct
6 Correct 130 ms 141280 KB Output is correct
7 Correct 136 ms 141788 KB Output is correct
8 Correct 129 ms 141556 KB Output is correct
9 Correct 133 ms 141816 KB Output is correct
10 Incorrect 137 ms 141660 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 141304 KB Output is correct
2 Correct 208 ms 146596 KB Output is correct
3 Correct 184 ms 146552 KB Output is correct
4 Correct 211 ms 146552 KB Output is correct
5 Correct 167 ms 145040 KB Output is correct
6 Correct 306 ms 154472 KB Output is correct
7 Correct 289 ms 154488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 141432 KB Output is correct
2 Correct 126 ms 141216 KB Output is correct
3 Correct 128 ms 141432 KB Output is correct
4 Correct 126 ms 141428 KB Output is correct
5 Correct 125 ms 141288 KB Output is correct
6 Correct 130 ms 141280 KB Output is correct
7 Correct 136 ms 141788 KB Output is correct
8 Correct 129 ms 141556 KB Output is correct
9 Correct 133 ms 141816 KB Output is correct
10 Incorrect 137 ms 141660 KB Output isn't correct