QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#861669#9975. Hitoshizukuucup-team6275#RE 0ms0kbC++233.1kb2025-01-18 19:07:182025-01-18 19:07:22

Judging History

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

  • [2025-01-18 19:07:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2025-01-18 19:07:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

#define rep(i, n) for (int i = 0; i < (n); i += 1)
#define len(a) ((int)(a).size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(324);
const ll inf = 1e18;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> gr(n);
    vector<ll> dist(n, inf);
    vector<int> ans(m, -1);
    dist[0] = 0;
    vector<pair<int, int>> edges;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        gr[u].push_back(v);
        gr[v].push_back(u);
        edges.push_back({u, v});
    }
    int k;
    cin >> k;
    vector<vector<int>> cuts;
    vector<int> marks(n);
    bool flag = true;
    for (int i = 0; i < k; ++i) {
        int t;
        cin >> t;
        vector<int> cur(t);
        for (auto &c : cur) {
            cin >> c;
            --c;
            ++marks[c];
        }
        sort(all(cur));
        vector<int> vc = {0};
        if (cur == vc) {
            marks[0]--;
            continue;
        }
        if (cur[0] == 0)
            flag = false;
        cuts.push_back(cur);
    }

    sort(all(cuts));
    priority_queue<pair<ll, int>> q;
    vector<int> used(n);
    q.push({0, 0});

    vector<int> prev_bad;
    int cur = 0;
    while (true) {
        vector<int> cur_bad = prev_bad;
        ll max_dist = 0;
        while (!q.empty()) {
            int v = q.top().second;
            q.pop();
            if (used[v])
                continue;
            used[v] = 1;
            max_dist = max(max_dist, dist[v]);

            for (auto to : gr[v]) {
                if (marks[to] == 0 && dist[to] >= inf) {
                    ++cur;
                    dist[to] = cur;
                    q.push({dist[to], to});
                } else if (marks[to] > 0) {
                    cur_bad.push_back(to);
                    max_dist = max(max_dist, dist[v] + 1);
                }
            }
        }

        if (cur_bad.empty())
            break;

        sort(all(cur_bad));
        cur_bad.erase(unique(all(cur_bad)), cur_bad.end());

        auto it = lower_bound(all(cuts), cur_bad);
        if (it == cuts.end() || (*it) != cur_bad) {
            flag = false;
            break;
        }

        prev_bad.clear();
        for (auto c : cur_bad) {
            marks[c]--;
            if (marks[c] == 0) {
                ++cur;
                dist[c] = cur;
                q.push({dist[c], c});
            } else {
                prev_bad.push_back(c);
            }
        }
    }

    if (flag) {
        cout << "Yes\n";
        for (int c = 0; c < m; ++c) {
            cout << abs(dist[edges[c].first] - dist[edges[c].second]) << " ";
        }
        cout << "\n";
    } else {
        cout << "No\n";
    }
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    int t;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

2
2
1 2
2 2
2 3
3 5
4 4
4 5
1
1 1
1 1000000000
1000000000 1000000000

output:


result: