結果

問題 No.1293 2種類の道路
ユーザー rokahikou1rokahikou1
提出日時 2020-11-21 11:09:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,362 bytes
コンパイル時間 3,297 ms
コンパイル使用メモリ 183,216 KB
実行使用メモリ 22,248 KB
最終ジャッジ日時 2023-09-30 21:41:33
合計ジャッジ時間 6,183 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
22,248 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:91:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   91 |     for(auto [root, list] : mp) {
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// UnionFind
struct UnionFind {
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; i++)
            par[i] = i;
    }
    int root(int x) {
        if(par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry)
            return;
        if(siz[rx] < siz[ry])
            swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    ll size(ll x) { return siz[root(x)]; }
};

void dfs(int v, const Graph &G, set<int> &se) {
    for(auto nv : G[v]) {
        if(se.count(nv))
            continue;
        se.insert(nv);
        dfs(nv, G, se);
    }
}

int main() {
    int N, D, W;
    cin >> N >> D >> W;
    UnionFind uf(N);
    rep(i, D) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    Graph G(N);

    rep(i, W) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        G[c].pb(d);
        G[d].pb(c);
    }
    map<int, vector<int>> mp;
    rep(i, N) { mp[uf.root(i)].pb(i); }
    ll res = 0;
    for(auto [root, list] : mp) {
        ll fst = list.size();
        set<int> se;
        for(auto v : list) {
            se.insert(v);
            dfs(v, G, se);
        }
        ll sec = se.size();
        res += fst * (sec - 1);
    }
    cout << res << endl;
}
0