Submission #8901819
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define dump(x) cout << (x) << endl #define Int int64_t #define fi first #define se second Int INF = 1e18; Int mod = 1e9+7; //Int mod = 998244353; Int par[100001]; Int root(Int x) { if (x == par[x]) { return x; } else { return par[x] = root(par[x]); } } void unite(Int x, Int y) { Int rx = root(x); Int ry = root(y); if (rx == ry) return; par[rx] = ry; } int main() { Int n, m; cin >> n >> m; vector<Int> a(m), b(m); for (Int i = 0; i < m; i++) { cin >> a[i] >> b[i]; } for (Int i = 1; i <= n; i++) { par[i] = i; } for (Int i = 0; i < m; i++) { unite(a[i], b[i]); } map<Int, Int> mp; for (Int i = 1; i <= n; i++) { mp[root(i)]++; } dump((Int)mp.size() - 1); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - 道路工事 |
User | keep_OC |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 907 Byte |
Status | AC |
Exec Time | 67 ms |
Memory | 7296 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 | 256 KB |
1.txt | AC | 1 ms | 256 KB |
10.txt | AC | 1 ms | 256 KB |
11.txt | AC | 1 ms | 256 KB |
12.txt | AC | 1 ms | 256 KB |
13.txt | AC | 1 ms | 256 KB |
14.txt | AC | 1 ms | 256 KB |
15.txt | AC | 44 ms | 1792 KB |
16.txt | AC | 38 ms | 7296 KB |
17.txt | AC | 37 ms | 7296 KB |
18.txt | AC | 24 ms | 7296 KB |
19.txt | AC | 67 ms | 3584 KB |
2.txt | AC | 1 ms | 256 KB |
3.txt | AC | 1 ms | 256 KB |
4.txt | AC | 1 ms | 256 KB |
5.txt | AC | 1 ms | 256 KB |
6.txt | AC | 1 ms | 256 KB |
7.txt | AC | 1 ms | 256 KB |
8.txt | AC | 1 ms | 256 KB |
9.txt | AC | 1 ms | 256 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |