結果
問題 | No.1293 2種類の道路 |
ユーザー |
![]() |
提出日時 | 2020-11-21 10:47:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,448 bytes |
コンパイル時間 | 2,051 ms |
コンパイル使用メモリ | 186,648 KB |
実行使用メモリ | 814,908 KB |
最終ジャッジ日時 | 2024-07-23 15:27:59 |
合計ジャッジ時間 | 5,362 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 MLE * 1 -- * 14 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:92:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 92 | for(auto [root, list] : mp) { | ^
ソースコード
#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;// UnionFindstruct 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, Graph G, vector<bool> &used, ll &cnt) {for(auto nv : G[v]) {if(used[nv])continue;cnt++;used[nv] = 1;dfs(nv, G, used, cnt);}}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) {vector<bool> used(N);ll fst = 0;ll sec = 0;for(auto v : list) {used[v] = 1;fst++;}for(auto v : list) {dfs(v, G, used, sec);}res += fst * (fst + sec - 1);}cout << res << endl;}