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....我晕死了dfs 老是re,请大牛帮忙看看: #include<iostream> using namespace std; const int MAX=1000005; int arc[1005][1005]; int visited[1005]={0}; int n,m; int shorest,sum; void dfs(int current) { if(!visited[current]) { visited[current]=1; for(int i=0;i!=n;i++) { if(arc[current][i]&&arc[current][i]<sum) sum=arc[current][i]; if(arc[current][i]) { if(i==(n-1)) { if(sum>shorest) shorest=sum; } else dfs(i); } } visited[current]=0; sum=MAX; } } int main() { int s; cin>>s; int counter=1; while(s--) { scanf("%d%d",&n,&m); for(int i=0;i!=m;i++) { for(int j=0;j!=m;j++) arc[i][j]=0; } for(int i=0;i!=m;i++) { int start,end; int value; scanf("%d%d%d",&start,&end,&value); arc[start-1][end-1]=value; } shorest=0; sum=MAX; dfs(0); cout<<"Scenario #"<<counter<<":"<<endl<<shorest<<endl; counter++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator