Submission #2501769
Source Code Expand
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int uf[(int)1e5+1];
int p[(int)1e5+1];
vector<int>edge[(int)1e5+1];
vector<int>cc[(int)1e5+1];
vector<int>dc[(int)1e5+1];
bool vst[(int)1e5+1];
void dfs(int k,int id){
cc[id].push_back(k);
dc[id].push_back(p[k]);
vst[k]=true;
int l=edge[k].size();
for(int i=0;i<l;i++){
if(!vst[edge[k][i]])dfs(edge[k][i],id);
}
}
int main(){
int n;
scanf("%d",&n);
int m;
scanf("%d",&m);
for(int i=0;i<n;i++){
scanf("%d",&p[i]);
p[i]--;
}
int x,y;
for(int i=0;i<m;i++){
scanf("%d%d",&x,&y);
x--;
y--;
edge[x].push_back(y);
edge[y].push_back(x);
}
int id=0;
for(int i=0;i<n;i++){
if(!vst[i]){
dfs(i,id);
id++;
}
}
int ans=0;
for(int i=0;i<id;i++){
sort(cc[i].begin(),cc[i].end());
sort(dc[i].begin(),dc[i].end());
int l=cc[i].size();
int j1=0,j2=0;
while(j1<l&&j2<l){
if(cc[i][j1]>dc[i][j2]){
j2++;
continue;
}
else if(cc[i][j1]<dc[i][j2]){
j1++;
continue;
}
else{
ans++;
j2++;
j1++;
}
}
}
printf("%d\n",ans);
}
Submission Info
Submission Time |
|
Task |
D - Equals |
User |
handsomeLiu |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1466 Byte |
Status |
AC |
Exec Time |
65 ms |
Memory |
14888 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:22:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:24:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&m);
^
./Main.cpp:26:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&p[i]);
^
./Main.cpp:31:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
^
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 |
4 ms |
7296 KB |
0_001.txt |
AC |
4 ms |
7296 KB |
0_002.txt |
AC |
4 ms |
7296 KB |
0_003.txt |
AC |
4 ms |
7296 KB |
1_004.txt |
AC |
20 ms |
8320 KB |
1_005.txt |
AC |
45 ms |
14848 KB |
1_006.txt |
AC |
65 ms |
14888 KB |
1_007.txt |
AC |
4 ms |
7296 KB |
1_008.txt |
AC |
4 ms |
7296 KB |
1_009.txt |
AC |
4 ms |
7296 KB |
1_010.txt |
AC |
4 ms |
7296 KB |
1_011.txt |
AC |
4 ms |
7296 KB |
1_012.txt |
AC |
4 ms |
7296 KB |
1_013.txt |
AC |
4 ms |
7296 KB |
1_014.txt |
AC |
5 ms |
7296 KB |
1_015.txt |
AC |
4 ms |
7296 KB |
1_016.txt |
AC |
4 ms |
7296 KB |
1_017.txt |
AC |
4 ms |
7296 KB |
1_018.txt |
AC |
19 ms |
8448 KB |
1_019.txt |
AC |
26 ms |
13952 KB |
1_020.txt |
AC |
26 ms |
13952 KB |
1_021.txt |
AC |
26 ms |
13952 KB |
1_022.txt |
AC |
64 ms |
13428 KB |