#include<stdio.h> int a[1000]; int main() { int i, n, m, sum, x, y; scanf("%d%d", &n, &m); for(i=0; i<n; ++i) a[i] = i; for(i=1; i<=m; ++i) { scanf("%d%d", &x, &y); a[y]=x; } for(sum=0, i=0; i<n; ++i) if(a[i] == i) ++sum; printf("%d ", sum); }
#include<stdio.h> int a[1000]; int main() { int i, n, m, sum, x, y; scanf("%d%d", &n, &m); for(i=0; i<n; ++i) a[i] = i; for(i=1; i<=m; ++i) { scanf("%d%d", &x, &y); a[y]=x; } for(sum=0, i=0; i<n; ++i) if(a[i] == i) ++sum; printf("%d ", sum); }