Submission #75559061


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int ll

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());

const int mod = 998244353;

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin >> t;
    while(t--){
        int n,m;
        cin >> n >> m;
        vector<int>dp(n+1);
        dp[1] = 1;
        vector<vi>adj(n+1);
        vector<int>deg(n+1);
        for(int i = 1; i<=m; i++){
            int x,y;
            cin >> x >> y;
            adj[x].push_back(y);
            deg[y]++;
        }
        queue<int>q;
        for(int i = 1; i<=n; i++){
            if(!deg[i])q.push(i);
        }
        while(sz(q)){
            int cur = q.front(); q.pop();
            for(int nxt: adj[cur]){
                deg[nxt]--;
                dp[nxt] += dp[cur]; dp[nxt] %= mod;
                if(deg[nxt] == 0)
                    q.push(nxt);
            }
        }
        cout << dp[n] << '\n';
    }
    return 0;
}

Submission Info

Submission Time
Task B - DAG
User kevinyang
Language C++23 (GCC 15.2.0)
Score 2
Code Size 1213 Byte
Status AC
Exec Time 47 ms
Memory 17352 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 2 / 2
Status
AC × 1
AC × 9
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3524 KiB
01_random_00.txt AC 18 ms 3616 KiB
01_random_01.txt AC 17 ms 3692 KiB
01_random_02.txt AC 27 ms 4200 KiB
01_random_03.txt AC 47 ms 15808 KiB
01_random_04.txt AC 27 ms 4156 KiB
01_random_05.txt AC 43 ms 15916 KiB
01_random_06.txt AC 35 ms 12716 KiB
01_random_07.txt AC 24 ms 17352 KiB