Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
迷之WA#include<cstdio> #include<cstring> #include<cstdlib> using namespace std; int k,n,m; int nm[200],cnt[1200],ans=0,e[1200]; bool a[1010][1010]; void dfs(int q) { e[q]=1; for(int i=1;i<=n;i++) if(a[q][i]) { if(!e[i])dfs(i); for(int j=1;j<=n;j++) if(a[i][j])a[q][j]=true; } } int main() { scanf("%d%d%d",&k,&n,&m); for(int i=1;i<=k;i++) scanf("%d",&nm[i]); for(int i=1;i<=m;i++) {int f,t;scanf("%d%d",&f,&t);a[f][t]=true;} for(int i=1;i<=n;i++) a[i][i]=true; for(int i=1;i<=k;i++) if(!e[nm[i]]) dfs(nm[i]); for(int i=1;i<=k;i++) for(int j=1;j<=n;j++) if(a[nm[i]][j])cnt[j]++; for(int i=1;i<=n;i++) if(cnt[i]==k)ans++; printf("%d",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator