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 |
Re:1470老是超时,那位高手能帮小弟看看不,谢谢了In Reply To:1470老是超时,那位高手能帮小弟看看不,谢谢了 Posted by:xiaoxiaoshan at 2008-08-25 17:55:35 > #include <iostream> > #include <map> > #include <vector> > using namespace std; > int *a,*b; int vnum; > struct Edge{ > int x,y; > }; > vector<Edge>pvect; > map<int,int>imap; > map<int,int>::iterator iter; > void solve() > { > int i,j,x,y; > b=new int[vnum+2]; > for(i=0;i<vnum+1;i++) b[i]=0; > for(i=0;i<pvect.size();i++){ > x=pvect[i].x; > y=pvect[i].y; > b[x]=true; > while(a[x]){ > b[a[x]]=true; > x=a[x]; > } > while(true){ > if(b[y]){ > iter=imap.find(y); > if(iter!=imap.end()) iter->second++; > else imap[y]=1; > break; > } > else y=a[y]; > } > for(j=0;j<vnum+1;j++) b[j]=0; > } > delete []b; > } > > int main() > { > int i,j,v,u,m; > char c; > Edge pnode; > while(scanf("%d",&vnum)){ > a=new int[vnum+2]; > for(i=0;i<vnum+1;i++) a[i]=0; > for(i=0;i<vnum;i++){ > scanf("%d",&v); > while(scanf("%c",&c)&&c!='('); > scanf("%d",&m); > while(scanf("%c",&c)&&c!=')'); > for(j=0;j<m;j++){ > scanf("%d",&u); > a[u]=v; > } > } > > scanf("%d",&m); > while(m--){ > while(scanf("%c",&c)&&c!='('); > scanf("%d%d",&u,&v); > pnode.x=u;pnode.y=v; > pvect.push_back(pnode); > while(scanf("%c",&c)&&c!=')'); > } > > solve(); > for(iter=imap.begin();iter!=imap.end();iter++) > printf("%d:%d\n",iter->first,iter->second); > > delete []a; > imap.clear(); > pvect.clear(); > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator