結果
問題 | No.1293 2種類の道路 |
ユーザー |
|
提出日時 | 2020-11-20 21:39:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 1,194 bytes |
コンパイル時間 | 725 ms |
コンパイル使用メモリ | 75,584 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-07-23 12:47:04 |
合計ジャッジ時間 | 3,254 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 22 |
コンパイルメッセージ
a.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp" #include<iostream> #include<vector> using namespace std; #line 2 "/home/kotatsugame/library/datastructure/UF.cpp" struct UF{ int n; vector<int>parent,rank; UF(int n_=0):n(n_),parent(n_),rank(n_,1) { for(int i=0;i<n_;i++)parent[i]=i; } int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;} bool same(int a,int b){return find(a)==find(b);} bool unite(int a,int b) { a=find(a),b=find(b); if(a==b)return false; if(rank[a]<rank[b]) { parent[a]=b; rank[b]+=rank[a]; } else { parent[b]=a; rank[a]+=rank[b]; } return true; } int size(int a){return rank[find(a)];} }; #line 5 "a.cpp" int N,A,B; int vis[1<<17]; main() { cin>>N>>A>>B; UF ua(N),ub(N); for(int i=0;i<A;i++) { int a,b;cin>>a>>b; a--,b--; ua.unite(a,b); } for(int i=0;i<B;i++) { int a,b;cin>>a>>b; a--,b--; ub.unite(a,b); } vector<vector<int> >AU(N); for(int i=0;i<N;i++)AU[ua.find(i)].push_back(i); long ans=0; int tm=0; for(const vector<int>&a:AU)if(!a.empty()) { long now=0; tm++; for(int u:a) { int id=ub.find(u); if(vis[id]<tm) { vis[id]=tm; now+=ub.size(u); } } ans+=now*a.size(); } cout<<ans-N<<endl; }