PAT(Advanced Level) 1003. Emergency(25) 最短路 + DFS

本文介绍了一道经典的图论问题——寻找两个城市间的最短路径,并在此基础上收集最多救援队伍的方法。通过SPFA算法找到最短路径后,再利用深度优先搜索遍历所有可能路径以找出满足条件的最大救援力量。

题目链接

Emergency

Time limit:1 seconds Memory limit:256 megabytes


Problem Description

IAs 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.

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

Output

2 4


题意:

求最短路的条数,以及最短路中的最大权

解题思路:

直接SPFA或Dijistra得出最短路,然后深搜一遍找最大权

Code:

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

const int maxn=500+5,maxm=500000;
const int INF = 0x3f3f3f3f;
struct EdgeNode
{
    int to,w,next;
};

EdgeNode edges[maxm];
int N,M;
int head[maxn],edge;
bool vis[maxn];
queue<int> que;
int dis[maxn];
int C1, C2;
int team[maxn];
int ans_len=0, ans_team=0,cnt=0;

void addedge(int u,int v,int c)
{
    edges[edge].w=c,edges[edge].to=v,edges[edge].next=head[u],head[u]=edge++;
}

void init()
{
    memset(head,-1,sizeof(head));
    edge=0;
}

void spfa(int s,int n)
{
    int u;
    for(int i=0;i<n;i++)
        dis[i]=INF;
    while(!que.empty())que.pop();
    que.push(s);
    vis[s]=true;
    dis[s]=0;
    while(!que.empty())
    {
        u = que.front();
        que.pop();
        vis[u] = false;
        for (int i = head[u]; i !=-1; i=edges[i].next)
        {
            int v = edges[i].to;
            int w = edges[i].w;
            if (dis[v]>dis[u]+w)
            {
                dis[v] = dis[u] + w;
                if(!vis[v])
                {
                    vis[v] = true;
                    que.push(v);
                }
            }
        }
    }
}

void DFS(int u,int teams,int len)
{
    //printf("%d %d %d\n", u, teams, len);
    if (u == C2 && ans_team < teams && len == ans_len)
    {
        ans_team = teams;
    }
    if (u == C2 &&len == ans_len)
    {
        cnt++;
    }
    if(len>=ans_len)
    {
        return;
    }
    vis[u] = true;
    for (int i = head[u]; i !=-1; i=edges[i].next)
    {
        int v = edges[i].to;
        int w = edges[i].w;
        if (!vis[v]&&len+w<=ans_len)
        {
            vis[v] = true;
            DFS(v, teams + team[v],len+w);
            vis[v] = false;
        }
    }
}


int main()
{
    init();
    cin >> N >> M >> C1 >> C2;
    for (int i = 0; i < N; i++)
    {
        cin >> team[i];
    }
    for (int i = 0; i < M;i++)
    {
        int u, v, c;
        cin >> u >> v >> c;
        addedge(u, v, c);
        addedge(v, u, c);
    }
    spfa(C1, N);
    ans_len = dis[C2];
    memset(vis, false, sizeof(vis));
    DFS(C1, team[C1], 0);
    cout << cnt << ' ' << ans_team << endl;
    return 0;
}

hspice仿真设计* 0.35um Logic Salicide Dual-gate Process with PLDD structure - THIN gate pMOS transistor .model pmos_3p3 PMOS +Level= 53 * * GENERAL PARAMETERS * *+lmin=3.5e-7 lmax=1.0e-5 wmin=4.0e-7 wmax=2.0e-5 +Tnom=25.0 +version =3.2 hspver=98.2 paramchk=1 *+Tox= 8.69E-09 *+Toxm= 8.69E-09 +Tox= toxp_tn +Toxm= toxp_tn +Xj= 1.0000000E-07 +Nch= 6.9300000E+16 +lln= 1.0000000 +lwn= 0.9690366 +wln= 1.1131999 +wwn= 0.1000000 *+lint= -2.5225001E-08 +lint= lintp_tn +ll= 0.00 +lw= -3.5000000E-15 +lwl= 2.5025000E-20 *+wint= 4.9900000E-08 +wint= wintp_tn +wl= 5.4900000E-14 +ww= -3.7500000E-09 +wwl= -1.2000000E-14 +Mobmod= 1 +binunit= 2 +Dwg= -2.0000000E-08 +Dwb= 0.00 wDwb= 6.0000000E-15 pDwb= -5.0000000E-22 * DIODE PARAMETERS +ACM= 12 +ldif=0.00 +hdif=3.5e-7 +rd= 0 +rs= 0 +rsc= 0 +rdc= 0 +calcacm= 1 +rsh= 0 * * THRESHOLD VOLTAGE PARAMETERS * *+Vth0= -0.8370000 +Vth0= vthop_tn +K1= 0.4883000 lK1= 9.9999990E-10 +K2= -1.0000000E-04 +K3= 0.7100000 +Dvt0= 2.4753001 +Dvt1= 0.3918000 +Dvt2= 1.5000000E-02 +Dvt0w= -0.5864000 +Dvt1w= 5.7000000E+05 +Dvt2w= -5.0000000E-02 +Nlx= 1.9200000E-07 +W0= 0.00 +K3b= 0.2240000 +Ngate= 1.0000000E+30 +Vfb= -0.4029894 * * MOBILITY PARAMETERS * +Vsat= 2.3000000E+05 pVsat= 3.5000000E-09 +Ua= 3.1400000E-09 +Ub= 6.9500000E-19 +Uc= 1.0700000E-10 +Rdsw= 1.7900000E+03 lRdsw= -2.2000000E-04 +Prwb= 0.1194000 +Prwg= 0.00 +Wr= 0.9209000 +U0= 2.7700000E-02 +A0= 1.5649250 +Keta= -1.6677311E-02 +A1= 0.00 +A2= 0.2960000 +Ags= 0.3275000 lAgs= 1.5300000E-07 +B0= 5.1200000E-07 +B1= 6.5000000E-07 * * SUBTHRESHOLD CURRENT PARAMETERS * +Voff= -0.1239000 +NFactor= 1.0000000 pNFactor= -3.5000000E-14 +Cit= 3.6750000E-04 +Cdsc= 9.3120000E-04 +Cdscb= 2.8855001E-04 +Cdscd= 0.00 +Eta0= 7.9114790E-02 lEta0= 4.1000000E-08 pEta0= -1.3000000E-14 +Etab= 0.00 +Dsub= 0.7003863 * * ROUT PARAMETERS * +Pclm= 3.2580400 +Pdiblc1= 1.5564860E-02 +Pdiblc2= 2.6037599E-04 +Pdiblcb= -0.1487453 +Drout= 0.1666364 +Pscbe1= 5.8755800E+08 +Pscbe2= 1.0000000E-08 +Pvag= 3.6609710 +Delta= 1.0000000E-02 +Alpha0= 1.9999997E-09 +Alpha1= 0.2700000 wAlpha1= -6.0000000E-08 +Beta0= 28.7999990 lBeta0= -1.1000000E-06 * * TEMPERATURE EFFECTS PARAMETERS * +kt1= -0.5600000 pkt1= 1.9999920E-15 +kt2= -4.6000000E-02 +At= 1.3600000E+05 pAt= -2.0000002E-09 +Ute= -1.4900000 lUte= 1.0000000E-07 pUte= -1.0000000E-14 +Ua1= 2.5800000E-09 pUa1= -5.4955000E-23 +Ub1= -5.6795000E-18 lUb1= -9.0000000E-25 wUb1= 3.3200000E-25 pUb1= 1.2999999E-31 +Uc1= -5.4000000E-10 lUc1= 4.4994500E-17 wUc1= 1.1000000E-16 pUc1= -9.9100000E-24 +Kt1l= 0.00 +Prt= 0.00 wPrt= 4.5000000E-04 pPrt= -5.0000000E-11 * * CAPACITANCE PARAMETERS * +Cj= 1.22954E-03 +Mj= 0.4149161 +Pb= 0.8488845 +Cjsw= 3.63341E-10 +Mjsw= 0.2938261 +Pbsw= 0.6648861 +Tcj= 9.489684E-04 +Tcjsw= 7.016366E-04 +Tpb= 1.612079E-03 +Tpbsw= 1.115389E-03 +JS=2.18e-7 +JSW=1.00e-13 +Nj=1.0 +Xti=3.0 *+Cgdo=1.05E-10 *+Cgso=1.05E-10 +Cgdo=cgdop_tn +Cgso=cgsop_tn +Cgbo=1.0E-13 +Capmod= 3 +NQSMOD= 0 +Elm= 5 +Xpart= 0 +cgsl= 1.50000E-10 +cgdl= 1.50000E-10 +ckappa= 0.6000000 +cf= 0.00 +clc= 1.0000000E-07 +cle= 0.6000000 +Dlc= -5.999996E-09 +Dwc= 4.990E-08 +Vfbcv= -0.2912 +Llc= 0 +Lwc= 0 +Wlc= 0 +Wwc= 0 +Lwlc= 0 +Wwlc= 0 +Acde= 0.5 +Moin= 15 +Noff= 2 +Voffcv= -0.03 * +noimod= 2 +NoiA= 3.88517E+17 +NoiB= 8092.033 +NoiC= 4.45351E-13 +Ef= 1 +Em= 41000000 * *------------------------------------------------------------------------------- * 0.35um Logic Salicide Dual-gate Process with PLDD structure - THIN gate nMOS transistor .model nmos_3p3 NMOS +Level= 53 * * GENERAL PARAMETERS * *+lmin=3.5e-7 lmax=1.0e-5 wmin=4.0e-7 wmax=2.0e-5 +Tnom=25.0 +version =3.2 hspver=98.2 paramchk=1 *+Tox= 7.69E-09 *+Toxm= 7.69E-09 +Tox= toxn_tn +Toxm= toxn_tn +Xj= 1.0000000E-07 +Nch= 2.0857000E+17 +lln= 1.0000000 +lwn= 1.0000000 +wln= 1.0000000 +wwn= 0.2296553 *+lint= 4.1240000E-08 +lint= lintn_tn +ll= 7.4999990E-15 +lw= 0.00 +lwl= 3.5036500E-21 *+wint= 6.3000000E-08 +wint= wintn_tn +wl= 0.00 +ww= -4.7510910E-10 +wwl= 0.00 +Mobmod= 1 +binunit= 2 +Dwg= 3.9968030E-15 +Dwb= 9.0300000E-09 * DIODE PARAMETERS +ACM= 12 +ldif=0.00 +hdif=3.5e-7 +rd= 0 +rs= 0 +rsc= 0 +rdc= 0 +calcacm= 1 +rsh= 0 * * THRESHOLD VOLTAGE PARAMETERS * *+Vth0= 0.6053000 +Vth0= vthon_tn +K1= 0.6780000 +K2= 0.00 +K3= 8.2500000E-06 +Dvt0= 4.95 pDvt0=-4e-14 +Dvt1= 0.7868235 +Dvt2= -5.0000000E-02 +Dvt0w= 4.3137080E-17 +Dvt1w= 7.0232080E+05 +Dvt2w= -5.0000000E-02 +Nlx= 1.2477851E-07 +W0= 8.6645000E-06 +K3b= 21.0000000 +Ngate= 1.0000000E+30 +Vfb= -0.8771217 * * MOBILITY PARAMETERS * +Vsat= 1.0079E+05 wVsat= 2.2500001E-02 +Ua= -4.7621650E-10 +Ub= 2.5418619E-18 pUb= -1.8000001E-32 +Uc= 7.8748400E-11 pUc= -3.0000002E-24 +Rdsw= 1.1460000E+03 lRdsw= -2.3999999E-05 wRdsw= -1.9199999E-04 pRdsw= 1.0000002E-11 +Prwb= 2.9500000E-02 +Prwg= -3.2596290E-09 +Wr= 1.0000000 +U0= 4.1371720E-02 +A0= 1.1916870 +Keta= -1.1081000E-02 lKeta= 4.0000000E-09 pKeta= 1.6500001E-15 +A1= 0.00 +A2= 1.0000000 +Ags= 0.2550000 pAgs= -2.5000000E-14 +B0= 5.1200000E-08 +B1= 0.00 * * SUBTHRESHOLD CURRENT PARAMETERS * +Voff= -0.1338250 +NFactor= 0.8875200 +Cit= 0.00 +Cdsc= 6.4040180E-04 +Cdscb= 0.00 +Cdscd= 0.00 +Eta0= 9.5819440E-02 pEta0= -3.3600000E-15 +Etab= -3.8400000E-02 pEtab= 2.0000002E-15 +Dsub= 0.7796514 * * ROUT PARAMETERS * +Pclm= 1.0838157 +Pdiblc1= 3.3256570E-03 +Pdiblc2= 1.0673814E-03 +Pdiblcb= 0.00 +Drout= 9.5951120E-02 *+Pscbe1= 6.0831020E+08 +Pscbe1= 8.5164E+08 +Pscbe2= 4.2862750E-05 +Pvag= 7.0746630E-02 +Delta= 2.1450121E-03 +Alpha0= 1.1000003E-06 pAlpha0= 1.5000000E-19 +Alpha1= 4.7757240 lAlpha1= -3.7000010E-07 pAlpha1= -8.2000000E-13 +Beta0= 22.4853550 lBeta0= 8.0000000E-08 * * TEMPERATURE EFFECTS PARAMETERS * +kt1= -0.2782500 lkt1= 1.2179998E-08 +kt2= -2.0000000E-02 lkt2= -1.0000000E-08 +At= 3.4000000E+04 +Ute= -1.7243394 wUte= 8.0000000E-08 +Ua1= -4.5460420E-13 +Ub1= 3.3460160E-21 +Uc1= -7.6289290E-12 +Kt1l= -2.2191699E-08 +Prt= 3.9055000E+02 * * CAPACITANCE PARAMETERS * +Cj= 1.023908E-03 +Mj= 0.3494655 +Pb= 0.7271543 +Cjsw= 2.26855E-10 +Mjsw= 0.2693402 +Pbsw= 0.9497247 +Tcj= 9.626137E-04 +Tcjsw= 7.622131E-04 +Tpb= 1.57771E-03 +Tpbsw= 2.341272E-03 +JS =3.05E-07 +JSW =1.40E-13 +Nj=0.9935 +Xti=3.0 +Cgdo=cgdon_tn +Cgso=cgson_tn +Cgbo=1.0E-13 +Capmod= 3 +NQSMOD= 0 +Elm= 5 +Xpart= 0 +cgsl= 2.2E-10 +cgdl= 2.2E-10 +ckappa= 0.6 +cf= 0.0 +clc= 1.0E-07 +cle= 0.6 +Dlc= 1.3E-09 +Dwc= 6.300E-08 +Vfbcv= -1 +Llc= 0 +Lwc= 0 +Wlc= 0 +Wwc= 0 +Lwlc= 0 +Wwlc= 0 +Acde= 0.5 +Moin= 15 +Noff= 1 +Voffcv= 0 * +noimod= 2 +NoiA= 1.68720E+17 +NoiB= 8799.889 +NoiC= -9.61545E-14 +Ef= 1.07018 +Em= 41000000 找出nmos和pmos的Tox,迁移率,沟道长度调制效应相关参数,计算并给出有效沟道 长度为0.5 μm时的沟道长度调制效应系数 解释Pclm
最新发布
09-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值