QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#544519#8942. Sugar Sweet 3ucup-team4821#TL 0ms0kbC++202.4kb2024-09-02 18:11:252024-09-02 18:11:25

Judging History

This is the latest submission verdict.

  • [2024-09-02 18:11:25]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-09-02 18:11:25]
  • Submitted

answer

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

const int N = 1000005, K = 61;
int n, m, k, in[N],  ans[N], last[K][K], sum[K];
vector<int> e[N], ch[K];
vector<int> to[K];
bitset<N> mark[K];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);

    cin >> n >> m;
    for(int i=1;i!=K;++i)
        to[i].reserve(N);
    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v);
        ++in[v];
    }

    while (m > 0) {
        for (int i = 1; i <= n; ++i) {
            if (!in[i] && !e[i].empty()) {
                int u = i;
                ch[++k].push_back(u);
                while (!e[u].empty()) {
                    int v = e[u].back();
                    e[u].pop_back();
                    --in[v];
                    u = v;
                    ch[k].push_back(v);
                    --m;
                }
                break;
            }
        }
    }
    assert(k <= 60);

    for (int u = n; u >= 1; --u) {
        vector<int> seq;
        for (int i = 1; i <= k; ++i) {
            if (!ch[i].empty() && ch[i].back() == u) {
                seq.push_back(i);
            }
        }
        if (seq.empty()) {
            ans[u] = 1;
            continue;
        }
        int t = seq.size();
        int i = seq[0];
        for (int y = 1; y < t; ++y) {
            int j = seq[y];
            for (int o = last[i][j]; o < (int) to[j].size(); ++o) {
                int x = to[j][o];
                if (!mark[i][x]) {
                    mark[i][x] = 1;
                    to[i].push_back(x);
                }
            }
        }
        mark[i][u] = 1;
        to[i].push_back(u);
        for (int y = 1; y < t; ++y) {
            int j = seq[y];
            for (int o = last[j][i]; o < (int) to[i].size(); ++o) {
                int x = to[i][o];
                if (!mark[j][x]) {
                    mark[j][x] = 1;
                    to[j].push_back(x);
                }
            }
        }
        ans[u] = to[i].size();
        for (int x = 0; x < t; ++x) {
            for (int y = 0; y < t; ++y) {
                last[seq[x]][seq[y]] = ans[u];
            }
        }
        for (auto j : seq) {
            assert(to[j].size() == ans[u]);
            ch[j].pop_back();
        }
    }

    for (int i = 1; i <= n; ++i) cout << ans[i] << " \n"[i == n];

    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

1 2 3 1

output:


result: