"p4822" [BJWC2012] Freeze

Source: Internet
Author: User

Description

"I'm going to be a magical girl!" ”
"So, at the cost of the soul, what do you want to get?" ”
"I'm going to seal everything about magic and miracles in a card?"

In the world after this desire is fulfilled, people enjoy the convenience of magic cards (Spellcard, aka Spell card).

Now, there's no need to make a contract or use magic! You're not going to give it a try?
For example, we use "freeze" as the keyword in The Magic Encyclopedia (Encyclopedia of Spells), and there are lots of interesting results.
For example, we know Cirno, her frozen magic will certainly have a corresponding spellcard. Of course, even more surprisingly, there is the magic of freezing time, the cirno of the frozen frog is really a little worse than these.
This suggests that many magical girls in the previous world had made a wish to control time, such as Akemi Homura, Sakuya Izayoi 、??
Of course, in the subject we are not to study history, but to study the application of magic.

Let's consider the simplest travel problem: Now there are N cities on this continent, M-two roads. City number is 1~n, we are in city 1th, need to City N, how to get the fastest to arrive?
Isn't that the shortest-circuit problem? We all know that we can use Dijkstra, Bellman-ford, Floyd-warshall and other algorithms to solve.
Now, we have a total of K-sheets that can make the time slow by 50% Spellcard, that is, we can choose to use a card when passing through a path, so that we can reduce the time we get through this road to the original half. It is important to note that:

    1. You can use up to one spellcard on a road.

    2. Using a single Spellcard only works on one road.

    3. You don't have to use all the Spellcard.

      Given the above information, your task is to find out how long it will take to get from City 1 to City N, in cases where you can use this spellcard that does not exceed the K-time deceleration.

Input

The first line consists of three integers: N, M, K. Next M-line, each line contains three integers: AI, Bi, Timei, indicates that there is a bidirectional path between AI and Bi, and it takes timei time to go through it without using Spellcard.

Output

Outputs an integer representing the minimum time from city 1th to City N.

A bare question of a layered graph.

Change the flight route a little bit.

Put Benquan \ (/2\) .

Hierarchical map words, you can Baidu to search, say this is still a lot of.

Note that we do not necessarily use all of the \ (spellcard\) to make \ (ans\) the smallest when we arrive at the destination.

So
\[ans=min (Ans,dis[n][i]) \]
and the array to open big, must open big!

代码

#include <cstdio> #include <queue> #include <cstring> #define R register#define N 20008using namespace    Std;inline void in (int &x) {int F=1;x=0;char s=getchar ();    while (s> ' 9 ' or s< ' 0 ') {if (s== '-') F=-1;s=getchar ();}    while (s>= ' 0 ' and s<= ' 9 ') {x=x*10+s-' 0 '; S=getchar ();} X*=f;} int head[n],tot,n,m,s,t,k;int dis[n][58],ans=2147483647;bool vis[n][58];struct cod{int u,v,w;}    edge[n*6+8];inline void Add (int x,int y,int z) {edge[++tot].u=head[x];    Edge[tot].v=y;    Edge[tot].w=z; Head[x]=tot;}    struct coc{int u,d,used;    BOOL operator < (const coc&a) const {return d>a.d;    }};inline void Dijkstra () {memset (dis,127,sizeof dis);    dis[s][0]=0;    priority_queue<coc>q;    Q.push (COC) {s,0,0});        while (!q.empty ()) {int u=q.top (). U,now=q.top (). Used;        Q.pop ();        if (Vis[u][now]) continue;        Vis[u][now]=true; for (R int i=head[u];i;i=edge[i].u) {if (Now<k and!VIS[EDGE[I].V][now+1] and DIS[EDGE[I].V][NOW+1]&GT;DIS[U][NOW]+EDGE[I].W/2) {Dis[edge[i].v][now+1]=dis[u][now                ]+EDGE[I].W/2;            Q.push (COC) {edge[i].v,dis[edge[i].v][now+1],now+1}); } if (!vis[edge[i].v][now] and DIS[EDGE[I].V][NOW]&GT;DIS[U][NOW]+EDGE[I].W) {DIS[EDG                E[I].V][NOW]=DIS[U][NOW]+EDGE[I].W;            Q.push (COC) {edge[i].v,dis[edge[i].v][now],now});    }}}}int Main () {in (n), in (m), in (k); s=1,t=n;        for (R int i=1,x,y,z;i<=m;i++) {in (x), in (Y), in (z);        Add (x, y, z);    Add (y,x,z);    } Dijkstra ();    for (R int i=0;i<=k;i++) ans=min (Ans,dis[t][i]); printf ("%d", ans);

"p4822" [BJWC2012] freezes

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.