[JLOI2011] 飞行路线

水一道裸分层图。

洛谷 P4568 传送门

发现自己现在好虚啊,写这种裸题都得思考一下。

数组还开小了,110000开成了100000,导致第一遍提交RE,90分......

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<queue>
 5 using namespace std;
 6 
 7 int n,m,k,s,t;
 8 int hd[10005],to[100005],nx[100005],len[100005],ec;
 9 int dis[110005],v[110005];
10 
11 void edge(int af,int at,int el)
12 {
13     to[++ec]=at;
14     len[ec]=el;
15     nx[ec]=hd[af];
16     hd[af]=ec;
17 }
18 
19 struct data
20 {
21     int p,d;
22     friend bool operator < (data q,data w)
23     {
24         return q.d>w.d;
25     }
26 };
27 
28 priority_queue<data>qq;
29 
30 void dijkstra()
31 {
32     memset(dis,0x3f,sizeof(dis));
33     dis[s]=0;
34     qq.push((data){s,0});
35     while(!qq.empty())
36     {
37         data nw=qq.top();
38         qq.pop();
39         if(v[nw.p])continue;
40         int pl=nw.p/n*n;
41         for(int i=hd[nw.p%n];i;i=nx[i])
42         {
43             int dest=to[i]+pl;
44             if((!v[dest])&&dis[dest]>nw.d+len[i])
45             {
46                 dis[dest]=nw.d+len[i];
47                 qq.push((data){dest,dis[dest]});
48             }
49             dest=to[i]+pl+n;
50             if(nw.p/n<k&&(!v[dest])&&dis[dest]>nw.d)
51             {
52                 dis[dest]=nw.d;
53                 qq.push((data){dest,dis[dest]});
54             }
55         }
56     }
57 }
58 
59 int main()
60 {
61     scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);
62     for(int i=1;i<=m;i++)
63     {
64         int u,v,w;
65         scanf("%d%d%d",&u,&v,&w);
66         edge(u,v,w);
67         edge(v,u,w);
68     }
69     dijkstra();
70     int ans=0x3f3f3f3f;
71     for(int i=k;i>=0;i--)ans=min(ans,dis[t+i*n]);
72     printf("%d",ans);
73     return 0;
74 }

 

posted @ 2018-11-08 15:53  cervusky  阅读(151)  评论(0编辑  收藏  举报

Contact with me