結果

問題 No.1293 2種類の道路
ユーザー rokahikou1rokahikou1
提出日時 2020-11-21 11:09:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,362 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 186,708 KB
実行使用メモリ 25,464 KB
最終ジャッジ日時 2024-07-23 15:28:40
合計ジャッジ時間 6,150 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 TLE * 1 -- * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:91:14: warning: 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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0