PAT1003—— Emergency

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input

5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1

Sample Output

2 4

dfs就行。注意是无向图,无向图,无向图!然后实参传错了,检查了一个小时TAT,真想抽自己。。
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include<cmath>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <stack>
#include <cctype>
using namespace std;
typedef unsigned long long ull;

int s,e,t[502],l[502][502],visit[502],n;
int tlen,tteam,num;

int dfs(int s,int team,int len)
{
    if(len>tlen)
        return 0;
    int i;
    if(s==e)
    {
        if(len<tlen)
        {
            num=1;
            tlen=len;
            tteam=team;
        }
        else if(len==tlen)
        {
            ++num;
            tteam=max(tteam,team);
        }
        return 0;
    }
    for(i=0;i<n;++i)
    {
        if(!visit[i]&&l[s][i]!=INT_MAX)
        {
            visit[i]=1;
            dfs(i,team+t[i],len+l[s][i]);
            visit[i]=0;
        }
    }
    return 0;
}

int main()
{
    int x,y,m,i,j,k,ans;

    cin>>n>>m>>s>>e;
    for(i=0;i<n;++i)
    {
        visit[i]=0;
        for(j=0;j<n;++j)
        {
            l[i][j]=INT_MAX;
        }
    }
    num=0;
    tlen=INT_MAX;
    for(i=0;i<n;++i)
    {
        scanf("%d",&t[i]);
    }
    for(i=0;i<m;++i)
    {
        scanf("%d%d%d",&x,&y,&k);
        l[x][y]=l[y][x]=min(k,l[x][y]);
    }
    visit[s]=1;
    dfs(s,t[s],0);
    cout<<num<<" "<<tteam;

    return 0;
}
时间: 2024-10-03 21:05:58

PAT1003—— Emergency的相关文章

PAT1003. Emergency (25)

As an emergency rescue team leader of a city, you are given a special map of your country.  The map shows several scattered cities connected by some roads.  Amount of rescue teams in each city and the length of each road between any pair of cities ar

1003 Emergency

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are

1003. Emergency (25)

时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in e

PAT1003 我要通过!

"答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于PAT的"答案正确"大派送 -- 只要读入的字符串满足下列条件,系统就输出"答案正确",否则输出"答案错误". 得到"答案正确"的条件是: 1. 字符串中必须仅有P, A, T这三种字符,不可以包含其它字符:2. 任意形如 xPATx 的字符串都可以获得"答案正确",其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串:3.

树莓派 Ubuntu Mate系统 开机进入 Emergency Mode

树莓派2B 重新刷的Ubuntu Mate15.10 系统, 一开始挺正常,  后来不知道怎么回事每次开机都会进入 如下画面. 估计是我经常直接拨电源,暴力关机导致的, 后来不断摸索,终于找到一个可行的方法,从 Emergency Mode 解脱: 1. 在 emergency mode 下 用root账户登录2. 执行 umount /dev/mmcblk0p23. 然后再执行 e2fsck -f -y -v -C 0 /dev/mmcblk0p24. reboot Ok. 所以这里还是 建议

UVALive 6093 Emergency Room --优先队列实现的模拟

题意:给n个医生,这些医生有一个上班时间,然后给一些病人,病人有一个到达的时间,以及一些诊断,诊断有property(优先级)和duration(诊断时间)这两个属性,每个病人可能要诊断多次,最后问每个病人的全部疗程完成离开医院的时间是多少. 分析:用优先队列存储诊断,病人,然后模拟一个诊断过程,完成病人的个数等于病人数的时候就结束.具体看代码吧. 代码: #include <iostream> #include <cstdio> #include <cstring>

解决:Android4.3锁屏界面Emergency calls only - China Unicom与EMERGENCY CALL语义反复

从图片中我们能够看到,这里在语义上有一定的反复,当然这是谷歌的原始设计.这个问题在博客上进行共享从表面上来看着实没有什么太大的意义,只是因为Android4.3在锁屏功能上比起老版本号做了非常大的修改,并且通过常规方法(Strings.xml中字符串)对该问题的定位会有非常大的难度,拿这个界面来说,EMERGENCY CALL并非Strings中值,而是  <string name="lockscreen_emergency_call">Emergency call<

PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)

1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount

A1003. Emergency (25)

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are