比赛 EYOI暨SBOI暑假快乐赛4th 评测结果 AAAATTTTTT
题目名称 醉笑圣城书 最终得分 40
用户昵称 lihaoze 运行时间 6.453 s
代码语言 C++ 内存使用 7.70 MiB
提交时间 2022-06-28 11:20:30
显示代码纯文本
#include <bits/stdc++.h>

using i64 = long long;
using PII = std::pair<int, int>;

struct Edge { int x, y, z; } edge[200010];

int fa[100010], n, m, ans, res;
int a, b;

int get(int x) {
    if (x == fa[x]) return x;
    return fa[x] = get(fa[x]);
}

int main() {
    freopen("zxscs.in", "r", stdin); 
    freopen("zxscs.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> m;
    for (int i = 1; i <= m; ++ i) {
        auto& [x, y, z] = edge[i];
        std::cin >> x >> y >> z;
        if (z == -1) a = x, b = y;
    }
    std::cin >> ans;
    for (int i = 1; i <= 10000010; ++ i) {
        res = 0;
        for (auto& j : edge) 
            if (j.x == a && j.y == b) j.z = i;
        std::sort(edge + 1, edge + m + 1, [](Edge a, Edge b) {
            return a.z < b.z;
        });
        for (int j = 1; j <= m; ++ j) fa[j] = j;
        for (int j = 1; j <= m; ++ j) {
            int x = get(edge[j].x);
            int y = get(edge[j].y);
            if (x == y) continue;
            fa[x] = y;
            res += edge[j].z;
        }
        if (ans == res) return std::cout << i << '\n', 0;
    }
    return 0;
}