Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

老是RE....我晕死了

Posted by timchou at 2009-08-08 13:11:54 on Problem 1797
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator