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:这代码错哪儿了大家来看看:In Reply To:这代码错哪儿了大家来看看: Posted by:123454321 at 2007-07-20 13:54:39 > #include <iostream> > #include <vector> > #include <cstdio> > #include <string> > using namespace std; > #define MAXN 5005 > bool in[MAXN]; > vector<int> mp[MAXN]; > int opt[MAXN]; > int tt[MAXN]; > int n,m; > > int go(int sta) > { > if(!in[sta]) { opt[sta]=1; return 1;} > if(opt[sta]!=-1) return opt[sta]; > register int i; > int tmpsum=0; > int len=mp[sta].size(); > for(i=0;i<len;i++) > { > tmpsum+=go(mp[sta][i]); > } > opt[sta]=tmpsum; > return tmpsum; > } > > int main() > { > register int i; > int x,y; > memset(opt,-1,sizeof(opt)); > scanf("%d%d",&n,&m);//n nodes ,m edges > for(i=1;i<=m;i++) > { > scanf("%d%d",&x,&y); > mp[y].push_back(x); > in[y]=true; > } > int sum=0; > go(n); > int max=0; > for(i=0;i<mp[n].size();i++) > { > if(max<opt[mp[n][i]]) max=opt[mp[n][i]]; > } > int cnt=0; > for(i=0;i<mp[n].size();i++) > { > if(max==opt[mp[n][i]]) > cnt++; > } > if(cnt>1) max=0; > printf("%d\n",max); > > return 0; > } > /* > 5 4 > 1 3 2 3 3 5 4 5 =2 > > 4 5 > 1 2 2 3 2 3 3 4 3 4 =0 > > 5 4 > 1 2 2 5 3 4 4 5 =0 > > 3 3 > 1 2 2 3 2 3 =0 > > 6 5 > 1 3 2 3 3 4 4 6 5 6 =2 > > 3 2 > 1 3 2 3 =0 > > 5 6 > 1 3 2 3 2 4 4 5 3 5 3 5 =0 > > 2 1 > 1 2 =1 > > > 5 5 > 1 3 3 5 2 3 2 4 4 5 =2 > > 4 4 > 1 2 2 3 2 3 3 4 =2 > 这些数据测地都对呀 > */ Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator