QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76332#2543. Edges, Colors and MSTLinshey#WA 4ms13984kbC++141.3kb2023-02-09 09:33:122023-02-09 09:33:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-09 09:33:14]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:13984kb
  • [2023-02-09 09:33:12]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std; const int maxn = 2e5 + 5; typedef long long ll;

int n, m, su[maxn], sv[maxn], sc[maxn];

struct edge { int v, w; }; vector<edge> T[maxn];

int P[maxn], M;

int fa[maxn], dep[maxn], a[maxn];

void DFS(int u, int f)
{
    fa[u] = f;
    dep[u] = dep[f] + 1;
    for (auto e : T[u]) if (e.v != f) a[e.v] = e.w, DFS(e.v, u);
}

int g[maxn];

inline int find(int u) { while (u != g[u]) u = g[u] = g[g[u]]; return u; }

int b[maxn], c;

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
    {
        scanf("%d%d%d", su + i, sv + i, sc + i);
        if (sc[i] == 1)
        {
            T[su[i]].push_back({ sv[i], i });
            T[sv[i]].push_back({ su[i], i });
        }
    }
    DFS(1, 0);
    for (int i = 1; i <= n; i++) g[i] = i;
    for (int i = 1; i <= m; i++) if (sc[i] == 0)
    {
        c = 0;
        for (int u = su[i], v = sv[i]; (u = find(u)) != (v = find(v)); )
        {
            if (dep[u] < dep[v]) b[++c] = a[v], g[v] = fa[v];
            else b[++c] = a[u], g[u] = fa[u];
        }
        sort(b + 1, b + c + 1);
        for (int j = 1; j <= c; j++) P[b[j]] = ++M;
        P[i] = ++M;
    }
    for (int i = 1; i <= m; i++) printf("%d ", P[i]); puts("");
}

详细

Test #1:

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

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: 4ms
memory: 13756kb

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'