社区讨论

求助,必关(只有第一个点A了)

P5603小 C 与桌游参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mdn3ku3s
此快照首次捕获于
2025/07/28 20:41
7 个月前
此快照最后确认于
2025/11/04 03:34
4 个月前
查看原帖
CPP
/*
    Ryan_L_F专属签名(防盗)
    lalalala~~
    I'm ambition is AK NOI.

    芙宁娜大人救救可怜的芙厨吧!
*/
// 纯属个人习惯,不用管

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

const int N = 5e5 + 10;
int n, m, in[N], tmp[N];
vector <int> mp[N], topo;

int main() {
    // auto start = steady_clock::now();


    // freopen("luogu.in", "r", stdin); 
    // freopen("ans.out", "w", stdout);
    
    scanf("%d %d", &n, &m);
    while (m --) {
        int u, v; scanf("%d %d", &u, &v);

        mp[v].push_back(u);
        in[u] ++;
    }

    priority_queue <int> q;
    memcpy(tmp, in, sizeof in);
    for (int i = 1; i <= n; i++)
        if (!in[i])
            q.push(i);

    while (!q.empty()) {
        int u = q.top(); q.pop();
        topo.push_back(u);

        for (auto v : mp[u]) {
            if (-- in[v] == 0)
                q.push(v);
        }
    }

    int ans = 0, maxn = 0;
    reverse(topo.begin(), topo.end());
    for (auto val : topo) {
        if (val > maxn) ans ++;
        maxn = max(maxn, val);
    }
    printf("%d\n", ans); topo.clear();

    for (int i = 1; i <= n; i++)
        if (!tmp[i])
            q.push(-i);

    while (!q.empty()) {
        int u = -q.top(); q.pop();
        topo.push_back(u);

        for (auto v : mp[u]) {
            if (-- tmp[v] == 0)
                q.push(-v);
        }
    }

    ans = 0, maxn = 0;
    reverse(topo.begin(), topo.end());
    for (auto val : topo) {
        if (val > maxn) ans ++;
        maxn = max(maxn, val);
    }
    printf("%d\n", ans);

    // auto end = steady_clock::now();
    // auto Time = duration_cast <microseconds> (end - start).count();
    // printf("Program execution time: %d\n", Time);
    return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...