Submission #28590106


Source Code Expand

#include <atcoder/all>
using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
// using P = pair<int,int>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

// const ll INF = (ll)2e18+9;
const int INF = (int)2e9+7;
// const ll MOD = (ll)1e9+9;
template<typename T>
void chmin(T &a, T b) { a = min(a, b); }
template<typename T>
void chmax(T &a, T b) { a = max(a, b); }

template<typename T>
void print(vector<T> v) {
    int n = v.size();
    rep(i,n) {
        if (i == 0) cout << v[i];
        else cout << ' ' << v[i];
    }
    cout << endl;
}

struct Edge {
    ll from, to, cost;
    int type; // type = 0: original, type = 1: query
    int idx;
};

bool operator<(const Edge &a, const Edge &b) {
    return a.cost < b.cost;
}

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

    vector<Edge> edges;
    // 元の辺の候補
    rep(i,m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        edges.push_back({a, b, c, 0, i});
    }

    // query による辺の候補
    rep(i, q) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        edges.push_back({u, v, w, 1, i});
    }
    sort(all(edges));

    // minimum spanning tree を構築
    vi ans(q, 0);
    dsu uf(n);
    for (auto edge : edges) {
        auto [from, to, cost, type, idx] = edge;
        if (!uf.same(from, to)) {
            if (type == 1) { // query の辺のとき
                ans[idx] = 1;
            } else { // 元の辺のとき
                uf.merge(from, to);
            }
        }
    }

    rep(i,q) cout << (ans[i] ? "Yes" : "No") << endl;
}

int main() {
    solve();
    return 0;
}

Submission Info

Submission Time
Task E - MST + 1
User goropikari
Language C++ (GCC 9.2.1)
Score 500
Code Size 2093 Byte
Status AC
Exec Time 593 ms
Memory 19796 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 13
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_tree_00.txt, 01_tree_01.txt, 01_tree_02.txt, 01_tree_03.txt, 01_tree_04.txt, 02_path_00.txt, 02_path_01.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 04_perfect_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3568 KiB
00_sample_01.txt AC 2 ms 3468 KiB
01_tree_00.txt AC 586 ms 19548 KiB
01_tree_01.txt AC 587 ms 19548 KiB
01_tree_02.txt AC 588 ms 19796 KiB
01_tree_03.txt AC 593 ms 19728 KiB
01_tree_04.txt AC 587 ms 19560 KiB
02_path_00.txt AC 586 ms 19648 KiB
02_path_01.txt AC 583 ms 19736 KiB
03_random_00.txt AC 585 ms 19684 KiB
03_random_01.txt AC 581 ms 19792 KiB
03_random_02.txt AC 582 ms 19796 KiB
04_perfect_00.txt AC 529 ms 19736 KiB