Zoj 3620 escape time II

Source: Internet
Author: User
Tags exit in

Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 4744

Escape time II Time Limit: 2 seconds memory limit: 65536 KB

There is a fire in LTR's home again. The fire can destroy all the things inTSeconds, so LTR has to escape inTSeconds. But there are some jewels in LTR's rooms, LTR love jewels very much so he wants to take his jewels as ready as possible before he goes to the exit. Assume thatITh room hasJiJewels. At the beginning LTR is in roomS, And the exit is in roomE.

Your job is to find a way that LTR can go to the exit in time and take his jewels as stored as possible.

Input

There are multiple test cases.
For each test case:
The 1st line contains 3 IntegersN(2 ≤N≤ 10 ),M,T(1 ≤T≤ 1000000) indicating the number of rooms, the number of edges between rooms and the escape time.
The 2nd line contains 2 integersSAndE, Indicating the starting room and the exit.
The 3rd line containsNIntegers,ITh intergerJi(1 ≤Ji≤ 1000000) indicating the number of jewels inITh room.
The nextMLines, every line contains 3 IntegersA,B,C, Indicating that there is a way between roomAAnd roomBAnd it will takeC(1 ≤C≤T) Seconds.

Output

For each test cases, you shocould print one line contains one integer the maximum number of jewels that LTR can take. If LTR can not reach the exit in time then output0Instead.

Sample Input
3 3 50 210 10 100 1 1 0 2 21 2 35 7 90 310 20 20 30 200 1 21 3 50 3 32 3 21 2 51 4 43 4 2
Sample output
3080
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxx = 20;int Edge[maxx][maxx];int val[maxx];bool vis[maxx];int big = 0,e,n,t;void dfs(int s, int num,int ju){    if(num>t)    return;    if(s == e)        if(ju > big && num<=t)            big = ju;    vis[s] = true;    for(int i=0;i<n;i++)    {        if(i!=s && Edge[s][i]<1e8 && !vis[i])        {            dfs(i,num + Edge[s][i],ju + val[i]);        }    }    vis[s] = false;}void Floyd(){    for(int i=0; i<n;i++)        for(int j=0; j<n; j++)            for(int k=0; k<n; k++)                if(Edge[j][i] + Edge[i][k] < Edge[j][k])                    Edge[j][k] = Edge[j][i] + Edge[i][k];}int main(){      int m;    int s;    while(~scanf("%d %d %d",&n,&m,&t))    {        memset(Edge,0x6,sizeof(Edge));        memset(val,0,sizeof(val));        memset(vis,0,sizeof(vis));        scanf("%d %d",&s,&e);        for(int i=0;i<n;i++)            scanf("%d",&val[i]);        for(int i=1;i<=m;i++)        {            int u,v,w;            scanf("%d %d %d",&u,&v,&w);            Edge[u][v] = Edge[v][u] = w;        }        Floyd();        big = 0;        vis[s] = true;        dfs(s,0,val[s]);        printf("%d\n",big);    }    return 0;}

 

Zoj 3620 escape time II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.