1 solutions
-
0
C++ :
#include<cstdio> #include<queue> using namespace std; int s,n,m,f[101],d[101]; queue<int>q; int main() { int i,a,b,fa,fb; while(~scanf("%d%d",&n,&m)) { for(i=1;i<=n;i++) f[i]=i,d[i]&=0; for(i=0;i<m;i++) { scanf("%d%d",&a,&b); f[b]=a; } for(s=0,i=1;i<=n;i++) if(i==f[i]) s++,q.push(i); printf("%d\n%d",s,q.front()); q.pop(); while(!q.empty()) printf(" %d",q.front()),q.pop(); } return 0; }Pascal :
program qi26790; var a:array[1..100]of longint; h,i,j,n,k,s:longint; begin read(n,k); for i:= 1 to n do a[i]:=0; for i:= 1 to k do begin read(h,j); a[j]:=h; end; s:=0; for i:= 1 to n do if a[i]=0 then inc(s); writeln(s); for i:=1 to n do if a[i]=0 then write(i,' '); end.
- 1
Information
- ID
- 18231
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By