QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#515025#8517. Interesting Pathsk1nsom#WA 2ms11324kbC++171.3kb2024-08-11 14:37:352024-08-11 14:37:35

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 14:37:35]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11324kb
  • [2024-08-11 14:37:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define int long long
#define PII pair<int, int>
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int n, m, dp[N], rd[N]; // dp[i]表示i节点出去到n的方案数
vector<int> e[N];
map<PII, int> vis;
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        if (y > x)
        {
            e[y].push_back(x);
            rd[x]++;
        }
    }
    queue<int> q;
    q.push(n);
    dp[n] = 1;
    while (!q.empty())
    {
        auto u = q.front();
        q.pop();
        for (auto to : e[u])
        {
            rd[to]--;
            if (rd[to] == 0)
                q.push(to);
            if (!vis[{u, to}])
            {
                vis[{u, to}] = 1;
                dp[to] += dp[u];
            }
        }
    }
    int js = 0;
    for (int i = n; i >= 1; i--)
        for (auto to : e[i])
            if (to == i - 1)
                js++;
    if (js == n - 1)
        cout << dp[1] - 1 << endl;
    else
        cout << dp[1] << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 10648kb

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: 0ms
memory: 10520kb

input:

5 3
1 3
2 3
2 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 11292kb

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 11324kb

input:

2 1
1 2

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'