Submission #64418621
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl '\n'
#define x first
#define y second
typedef pair<int,int>pii;
const int N = 1e6 + 10;
string s;
int n,m;
int fa[N];
int a[N];
int cnt;
int find(int x){
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= n; i++) fa[i] = i;
for(int i = 1; i <= m; i++) {
int u , v;
cin >> u >> v;
if(find(u) == find(v)) cnt++;
else{
fa[find(u)] = find(v);
}
}
cout << cnt;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// int T;
// cin>>T;
// while(T--)
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Make it Forest |
| User | YANG666 |
| Language | C++ 20 (gcc 12.2) |
| Score | 350 |
| Code Size | 671 Byte |
| Status | AC |
| Exec Time | 26 ms |
| Memory | 4420 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 02_min_00.txt, 02_min_01.txt, 03_max_00.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3464 KiB |
| 00_sample_01.txt | AC | 1 ms | 3488 KiB |
| 00_sample_02.txt | AC | 1 ms | 3568 KiB |
| 01_random_00.txt | AC | 25 ms | 4080 KiB |
| 01_random_01.txt | AC | 19 ms | 4192 KiB |
| 01_random_02.txt | AC | 26 ms | 4168 KiB |
| 01_random_03.txt | AC | 26 ms | 4224 KiB |
| 01_random_04.txt | AC | 24 ms | 3884 KiB |
| 01_random_05.txt | AC | 16 ms | 4356 KiB |
| 01_random_06.txt | AC | 25 ms | 3840 KiB |
| 01_random_07.txt | AC | 26 ms | 4360 KiB |
| 01_random_08.txt | AC | 18 ms | 3984 KiB |
| 01_random_09.txt | AC | 19 ms | 4172 KiB |
| 01_random_10.txt | AC | 24 ms | 3960 KiB |
| 01_random_11.txt | AC | 26 ms | 4420 KiB |
| 02_min_00.txt | AC | 1 ms | 3452 KiB |
| 02_min_01.txt | AC | 1 ms | 4236 KiB |
| 03_max_00.txt | AC | 15 ms | 3640 KiB |