QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227157#2543. Edges, Colors and MSTJooDdaeWA 2ms9680kbC++201.1kb2023-10-26 23:58:232023-10-26 23:58:23

Judging History

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

  • [2023-10-26 23:58:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9680kb
  • [2023-10-26 23:58:23]
  • 提交

answer

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

int n, m, ans[200200], lev[200200], p[200200], cnt;
vector<array<int, 2>> v[200200];
array<int, 2> par[200200];

int find(int x) {
    if(x == p[x]) return x;
    return p[x] = find(p[x]);
}

void dfs(int u, int p) {
    lev[u] = lev[p]+1;
    for(auto [x, id] : v[u]) if(x != p) {
        par[x] = {u, id};
        dfs(x, u);
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    vector<array<int, 3>> edge;
    for(int i=1;i<=m;i++) {
        int x, y, c; cin >> x >> y >> c;
        if(c) v[x].push_back({y, i}), v[y].push_back({x, i});
        else edge.push_back({x, y, i});
    }

    dfs(1, 0);
    iota(p+1, p+1+n, 1);

    for(auto [x, y, i] : edge) {
        x = find(x), y = find(y);
        vector<int> l;
        while(x != y) {
            if(lev[x] < lev[y]) swap(x, y);
            l.push_back(par[x][1]), x = p[x] = find(par[x][0]);
        }
        sort(l.begin(), l.end());
        for(auto x : l) ans[x] = ++cnt;
        ans[i] = ++cnt;
    }

    for(int i=1;i<=m;i++) cout << ans[i] << " ";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9540kb

input:

4 5
1 2 0
2 3 1
3 4 1
2 4 0
1 3 1

output:

3 1 4 5 2 

result:

ok 5 number(s): "3 1 4 5 2"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 9680kb

input:

9 15
1 4 1
3 5 1
3 9 0
1 3 0
2 5 0
5 8 0
6 9 0
8 9 0
1 7 1
1 8 1
6 8 1
4 9 1
2 4 1
3 4 1
4 6 0

output:

4 6 3 5 8 10 12 13 0 9 11 1 7 2 14 

result:

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