結果
問題 | No.1390 Get together |
ユーザー | chocorusk |
提出日時 | 2021-02-12 21:28:10 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 183 ms / 2,000 ms |
コード長 | 1,496 bytes |
コンパイル時間 | 1,471 ms |
コンパイル使用メモリ | 130,508 KB |
実行使用メモリ | 13,364 KB |
最終ジャッジ日時 | 2023-09-27 02:52:07 |
合計ジャッジ時間 | 6,512 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
8,196 KB |
testcase_01 | AC | 6 ms
8,064 KB |
testcase_02 | AC | 4 ms
8,008 KB |
testcase_03 | AC | 8 ms
8,148 KB |
testcase_04 | AC | 6 ms
8,412 KB |
testcase_05 | AC | 8 ms
8,172 KB |
testcase_06 | AC | 7 ms
8,144 KB |
testcase_07 | AC | 7 ms
8,132 KB |
testcase_08 | AC | 6 ms
8,240 KB |
testcase_09 | AC | 9 ms
8,160 KB |
testcase_10 | AC | 5 ms
8,088 KB |
testcase_11 | AC | 6 ms
8,072 KB |
testcase_12 | AC | 7 ms
8,072 KB |
testcase_13 | AC | 6 ms
8,076 KB |
testcase_14 | AC | 6 ms
8,028 KB |
testcase_15 | AC | 6 ms
7,984 KB |
testcase_16 | AC | 115 ms
10,420 KB |
testcase_17 | AC | 170 ms
13,248 KB |
testcase_18 | AC | 122 ms
10,440 KB |
testcase_19 | AC | 180 ms
13,256 KB |
testcase_20 | AC | 183 ms
13,200 KB |
testcase_21 | AC | 181 ms
13,188 KB |
testcase_22 | AC | 143 ms
12,316 KB |
testcase_23 | AC | 144 ms
12,128 KB |
testcase_24 | AC | 143 ms
12,320 KB |
testcase_25 | AC | 161 ms
13,364 KB |
testcase_26 | AC | 160 ms
13,364 KB |
testcase_27 | AC | 161 ms
13,236 KB |
testcase_28 | AC | 160 ms
13,200 KB |
testcase_29 | AC | 159 ms
13,364 KB |
testcase_30 | AC | 160 ms
13,292 KB |
testcase_31 | AC | 159 ms
13,364 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <stack> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; struct unionfind{ int cnt; vector<int> par, sz; unionfind() {} unionfind(int n):par(n), sz(n, 1), cnt(n){ for(int i=0; i<n; i++) par[i]=i; } int find(int x){ if(par[x]==x) return x; return par[x]=find(par[x]); } void unite(int x, int y){ x=find(x); y=find(y); if(x==y) return; cnt--; if(sz[x]>sz[y]) swap(x, y); par[x]=y; sz[y]+=sz[x]; } bool same(int x, int y){ return find(x)==find(y); } int size(int x){ return sz[find(x)]; } }; int main() { int n, m; cin>>n>>m; unionfind uf(m); vector<int> v[200020]; for(int i=0; i<n; i++){ int b, c; cin>>b>>c; b--; c--; v[c].push_back(b); } for(int i=0; i<n; i++){ if(!v[i].empty()){ for(int j=0; j<(int)v[i].size()-1; j++){ uf.unite(v[i][j], v[i][j+1]); } } } cout<<m-uf.cnt<<endl; return 0; }