Submission #2498122
Source Code Expand
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
inline void Fail(){printf("0");exit(0);}
const int maxn=100005;
int n,m,ans;
int f[maxn],p[maxn];
int Find(int x){return f[x]==x?x:f[x]=Find(f[x]);}
void Union(int x,int y){x=Find(x);y=Find(y);f[x]=y;}
int main(){
scanf("%d%d",&n,&m);
rep(i,n)scanf("%d",&p[i]),f[i]=i,p[i]--;
rep(i,m){
int u,v;
scanf("%d%d",&u,&v);
u--;v--;
Union(p[u],p[v]);
}
rep(i,n)if(Find(i)==Find(p[i]))ans++;
printf("%d",ans);
return 0;
}
/*
Input:
-----------------
Output:
*/
Submission Info
Submission Time |
|
Task |
D - Equals |
User |
little_waxberry |
Language |
C++ (GCC 5.4.1) |
Score |
400 |
Code Size |
828 Byte |
Status |
AC |
Exec Time |
35 ms |
Memory |
1024 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:25:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.cpp:26:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i,n)scanf("%d",&p[i]),f[i]=i,p[i]--;
^
./Main.cpp:29:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
^
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 |
16 ms |
256 KB |
1_005.txt |
AC |
28 ms |
1024 KB |
1_006.txt |
AC |
32 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 |
2 ms |
256 KB |
1_018.txt |
AC |
14 ms |
256 KB |
1_019.txt |
AC |
11 ms |
1024 KB |
1_020.txt |
AC |
11 ms |
1024 KB |
1_021.txt |
AC |
11 ms |
1024 KB |
1_022.txt |
AC |
35 ms |
1024 KB |