QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543816#8517. Interesting PathsHTensor#WA 1ms5936kbC++171.2kb2024-09-01 20:39:352024-09-01 20:39:35

Judging History

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

  • [2024-09-01 20:39:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5936kb
  • [2024-09-01 20:39:35]
  • 提交

answer

#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x  << ": " << x << "\n"
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
const int inf = 0x3f3f3f3f3f3f3f3fLL;

const int N = 1e5 + 5;
vector<int> adj[N];

void solve() {
    int n, m; cin >> n >> m;
    
    vector<int> rd(n + 1), vis(n + 1), dp(n + 1);
    for(int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        adj[v].push_back(u);
        rd[u]++;
    }

    queue<int> Q; Q.push(n);
    for(int i = 1; i < n; i++) if(!rd[i]) Q.push(i);
    dp[n] = 0;
    while(!Q.empty()) {
        int u = Q.front(); Q.pop();
        for(auto v : adj[u]) {
            // if(vis[v]) continue;
            dp[v] = max(dp[v], dp[u] + 1);
            rd[v]--;
            // Q.push(v);
            if(!rd[v]) Q.push(v);
        }
    }

    cout << dp[1] << "\n";
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    while(T--) solve();
    return 0;
}

/*
5 7
1 3
3 5
1 2
2 3
3 4
4 5
2 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5936kb

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: -100
Wrong Answer
time: 1ms
memory: 5912kb

input:

5 3
1 3
2 3
2 5

output:

1

result:

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