• CodeForcesGym 100753E Change of Scenery


    Change of Scenery

    Time Limit: 10000ms
    Memory Limit: 262144KB
    This problem will be judged on CodeForcesGym. Original ID: 100753E
    64-bit integer IO format: %I64d      Java class name: (Any)
     
    解题:最短路
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef pair<int,int> pii;
     4 const int maxn = 10010;
     5 struct arc{
     6     int to,cost,next;
     7     arc(int x = 0,int y = 0,int z = -1){
     8         to = x;
     9         cost = y;
    10         next = z;
    11     }
    12 }e[2010000];
    13 int head[maxn],cnt[maxn],d[maxn],tot,N,M,K;
    14 void add(int u,int v,int w){
    15     e[tot] = arc(v,w,head[u]);
    16     head[u] = tot++;
    17 }
    18 priority_queue<pii,vector<pii>,greater<pii>>q;
    19 bool done[maxn];
    20 void dijkstra(){
    21     while(!q.empty()) q.pop();
    22     memset(d,0x3f,sizeof d);
    23     memset(cnt,0,sizeof cnt);
    24     q.push(pii(d[1] = 0,cnt[1] = 1));
    25     while(!q.empty()){
    26         int u = q.top().second;
    27         q.pop();
    28         if(done[u]) continue;
    29         done[u] = true;
    30         for(int i = head[u]; ~i; i = e[i].next){
    31             if(d[e[i].to] > d[u] + e[i].cost){
    32                 d[e[i].to] = d[u] + e[i].cost;
    33                 cnt[e[i].to] = cnt[u];
    34                 q.push(pii(d[e[i].to],e[i].to));
    35             }else if(d[e[i].to] == d[u] + e[i].cost)
    36                 cnt[e[i].to]++;
    37         }
    38     }
    39 }
    40 int main(){
    41     int x,u,v,w;
    42     while(~scanf("%d%d%d",&N,&M,&K)){
    43         memset(head,-1,sizeof head);
    44         while(K--) scanf("%d",&x);
    45         for(int i = tot = 0; i < M; ++i){
    46             scanf("%d%d%d",&u,&v,&w);
    47             add(u,v,w);
    48             add(v,u,w);
    49         }
    50         dijkstra();
    51         puts(cnt[N] > 1?"yes":"no");
    52     }
    53     return 0;
    54 }
    55 /*
    56 3 3 3
    57 1 2 3
    58 1 2 1
    59 2 3 2
    60 1 3 3
    61 4 5 2
    62 1 4
    63 1 2 2
    64 2 4 1
    65 1 3 1
    66 3 4 2
    67 1 4 2
    68 */
    View Code
  • 相关阅读:
    将文件写进数据库的方法
    立个Flag
    JQuery_学习1
    js制作一个简单的选项卡
    输出数据库中的表格的内容(pdo连接)
    不饮鸡汤的寂寞先生
    详细谈Session
    详细谈Cookie
    php字符串操作函数练习2
    ios开发网络学习五:MiMEType ,多线程下载文件思路,文件的压缩和解压缩
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4856144.html
Copyright © 2020-2023  润新知