結果
| 問題 |
No.1390 Get together
|
| コンテスト | |
| ユーザー |
zumin
|
| 提出日時 | 2021-02-22 21:05:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 347 ms / 2,000 ms |
| コード長 | 602 bytes |
| コンパイル時間 | 901 ms |
| コンパイル使用メモリ | 85,612 KB |
| 実行使用メモリ | 32,256 KB |
| 最終ジャッジ日時 | 2024-09-21 16:40:34 |
| 合計ジャッジ時間 | 6,419 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
int main(){
int n,m;
cin>>n>>m;
vector<set<int>> cnt(n);
dsu uf(m);
int ans=0;
for(int i=0;i<n;i++){
int b,c;
cin>>b>>c;
b--;c--;
cnt[c].insert(b);
}
for(int i=0;i<n;i++){
set<int> s;
for(auto v:cnt[i]){
s.insert(uf.leader(v));
}
ans+=max(0,(int)s.size()-1);
for(auto v:s){
uf.merge(*s.begin(),v);
}
}
cout<<ans<<endl;
return 0;
}
zumin