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 |
为啥我都用了cin,cout怎么还是超时啊????#include<iostream> using namespace std; const int maxn = 201; const int maxm = 201; struct gtype { int x, y, next; }; gtype g[maxm]; int first[maxn]; int link[maxn]; bool used[maxn]; int n, m, tot; void add(int x, int y) { tot++; g[tot].x = x; g[tot].y = y; g[tot].next = first[x]; first[x] = tot; } bool find(int s) { int temp; temp = first[s]; while(temp != -1) { if( !used[g[temp].y]) { used[g[temp].y] = true; if(link[g[temp].y]==0 || find(link[g[temp].y])) { link[g[temp].y] = s; return true; } } temp = g[temp].next; } return false; } int main() { int i, j, k, x, y; int ans; while(cin>>n>>m) { for(x=1; x<=n; x++) { cin>>k; for(j=1; j<=k; j++) { cin>>y; add(x, y); } } memset(link, 0, sizeof(link)); for(i=1; i<=n; i++) { memset(used, false, sizeof(used)); find(i); } ans = 0; for(i=1; i<=n; i++) { if(link[i] != 0) { ans++; //cout<<link[i]<<" "<<i<<endl; } } //printf("%d\n",ans); cout<<ans<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator