Submission #4015966
Source Code Expand
#include <bits/stdc++.h> #define MAX_N 100000 using namespace std; template <class T> inline void read(T &x) { x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n, m, a[MAX_N+5], fa[MAX_N+5]; int getf(int x) {return fa[x] == x ? x : fa[x] = getf(fa[x]);} int main() { read(n), read(m); for (int i = 1; i <= n; i++) fa[i] = i; for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= m; i++) { int u, v; read(u), read(v); u = getf(u), v = getf(v); if (u ^ v) fa[u] = v; } int tot = 0; for (int i = 1; i <= n; i++) tot += getf(i) == getf(a[i]); return printf("%d\n", tot), 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Equals |
User | Azrael_Death |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 727 Byte |
Status | AC |
Exec Time | 20 ms |
Memory | 1024 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
0_003.txt | AC | 1 ms | 256 KB |
1_004.txt | AC | 8 ms | 256 KB |
1_005.txt | AC | 16 ms | 1024 KB |
1_006.txt | AC | 18 ms | 1024 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 1 ms | 256 KB |
1_009.txt | AC | 1 ms | 256 KB |
1_010.txt | AC | 1 ms | 256 KB |
1_011.txt | AC | 1 ms | 256 KB |
1_012.txt | AC | 1 ms | 256 KB |
1_013.txt | AC | 1 ms | 256 KB |
1_014.txt | AC | 2 ms | 256 KB |
1_015.txt | AC | 1 ms | 256 KB |
1_016.txt | AC | 1 ms | 256 KB |
1_017.txt | AC | 1 ms | 256 KB |
1_018.txt | AC | 7 ms | 256 KB |
1_019.txt | AC | 6 ms | 1024 KB |
1_020.txt | AC | 6 ms | 1024 KB |
1_021.txt | AC | 7 ms | 1024 KB |
1_022.txt | AC | 20 ms | 1024 KB |