Submission #17050582


Source Code Expand

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;

	dsu uf(N);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}

	int ans = uf.groups().size() - 1;
	cout << ans << endl;
}





Submission Info

Submission Time
Task C - Connect Cities
User hamayanhamayan
Language C++ (GCC 9.2.1 with AC Library)
Score 300
Code Size 1643 Byte
Status AC
Exec Time 34 ms
Memory 8944 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 1
AC × 21
Set Name Test Cases
Sample example0.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, example0.txt
Case Name Status Exec Time Memory
000.txt AC 15 ms 3848 KiB
001.txt AC 10 ms 4080 KiB
002.txt AC 14 ms 6284 KiB
003.txt AC 22 ms 4732 KiB
004.txt AC 28 ms 4748 KiB
005.txt AC 16 ms 5984 KiB
006.txt AC 30 ms 6500 KiB
007.txt AC 14 ms 8944 KiB
008.txt AC 33 ms 7344 KiB
009.txt AC 22 ms 4236 KiB
010.txt AC 33 ms 7308 KiB
011.txt AC 34 ms 7680 KiB
012.txt AC 33 ms 7248 KiB
013.txt AC 33 ms 7680 KiB
014.txt AC 34 ms 7720 KiB
015.txt AC 32 ms 7692 KiB
016.txt AC 34 ms 7676 KiB
017.txt AC 33 ms 7556 KiB
018.txt AC 34 ms 7608 KiB
019.txt AC 32 ms 7576 KiB
example0.txt AC 2 ms 3660 KiB