Submission #1215029
Source Code Expand
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
#define INF 1 << 30
#define MOD 1000000007;
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {-1, 1, 0, 0};
struct UF {
vector<int> par;
UF(int n) : par(n) { for (int i = 0; i < n; i++) par[i] = i; }
int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
bool same(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; par[x] = y; }
};
int main() {
int n, m;
cin >> n >> m;
UF uf(101010);
rep (i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
uf.unite(a, b);
}
vb flag(n);
rep (i, n) {
flag[uf.find(i)] = true;
}
int ans = 0;
rep (i, n) if (flag[i]) ans++;
ans--;
D(ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - 道路工事 |
User |
KokiYmgch |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2036 Byte |
Status |
AC |
Exec Time |
61 ms |
Memory |
640 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt |
All |
0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt |
Case Name |
Status |
Exec Time |
Memory |
0.txt |
AC |
1 ms |
640 KB |
1.txt |
AC |
1 ms |
640 KB |
10.txt |
AC |
1 ms |
640 KB |
11.txt |
AC |
1 ms |
640 KB |
12.txt |
AC |
1 ms |
640 KB |
13.txt |
AC |
1 ms |
640 KB |
14.txt |
AC |
1 ms |
640 KB |
15.txt |
AC |
43 ms |
640 KB |
16.txt |
AC |
2 ms |
640 KB |
17.txt |
AC |
2 ms |
640 KB |
18.txt |
AC |
2 ms |
640 KB |
19.txt |
AC |
61 ms |
640 KB |
2.txt |
AC |
1 ms |
640 KB |
3.txt |
AC |
1 ms |
640 KB |
4.txt |
AC |
1 ms |
640 KB |
5.txt |
AC |
1 ms |
640 KB |
6.txt |
AC |
1 ms |
640 KB |
7.txt |
AC |
1 ms |
640 KB |
8.txt |
AC |
1 ms |
640 KB |
9.txt |
AC |
1 ms |
640 KB |
sample1.txt |
AC |
1 ms |
640 KB |
sample2.txt |
AC |
1 ms |
640 KB |