1003 Emergency (25分)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int cnum;
int rnum;
int start,end1;
int road[510][510];
vector cteam;//vector定义在全局变量时不能用未赋值的变量声明大小,可以cteam.resize(cnum);
int minlen=-1,maxteam=0;
int totalnum=0;
bool getcity[510]={false};
void dfs(int s,int len,int team)
{
    if(minlen>0 && len>minlen)
        return;
    if(s==end1)
    {
        if(minlen<0||len0 && getcity[i]==false)
        {
            getcity[i]=true;
            dfs(i,len+road[s][i],team+cteam[i]);
            getcity[i]=false;
        }
    }
    return;
}
int main()
{
    cin>>cnum>>rnum>>start>>end1;
    cteam.resize(cnum);
    for(int i=0;i>cteam[i];
    int a,b;
    for(int i=0;i>a>>b;
        cin>>road[a][b];
        road[b][a]=road[a][b];
    }
    getcity[start]=true;
    dfs(start,0,cteam[start]);
    cout<

 

你可能感兴趣的:(PAT)