zoukankan      html  css  js  c++  java
  • ccf行车路线

    #include<bits/stdc++.h>
    using namespace std;
    const long long INF = 1e18;
    int n,m;
    struct node{
    int to;
    long long cost;
    };
    
    struct edge{
    int id; 
    long long cost;
    int len;
    bool operator < (const edge & a)const {
    return cost > a.cost;
    }
    };
    
    vector<node> G[510][2];
    long long d[510];
    priority_queue<edge>que;
    
    long long p2(long long a){
    return a * a;
    }
    
    int solve(){
    fill(d,d+n+1,INF);
    d[1] = 0; 
    que.push({1,0,0});
    while(!que.empty() ){
    edge a = que.top();
    que.pop();
    int v = a.id;
    if(v == n)
    break;
    if(d[v] < a.cost)
    continue;
    for(int i=0;i<G[v][0].size();i++){
    node e = G[v][0][i];
    if(d[e.to] > d[v] + e.cost){
    d[e.to] = d[v] + e.cost;
    que.push(edge{e.to,d[e.to],0});
    }
    }
    for(int i=0;i<G[v][1].size();i++){
    node e = G[v][1][i];
    int cost = p2(a.len+e.cost)-p2(a.len);
    if(d[e.to] > d[v] + cost){
    d[e.to] = d[v] + cost;
    que.push(edge{e.to,d[e.to],a.len+e.cost}); 
    }
    }
    } 
    return d[n]; 
    }
    
    int main ()
    {
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
    int t,a,b;
    long long c;
    scanf("%d %d %d %lld",&t,&a,&b,&c);
    G[a][t].push_back({b,c}); 
    G[b][t].push_back({a,c}); 
    }
    cout << solve() <<endl;
    return 0; 
    }
    

     80分的

    转载于:https://www.cnblogs.com/Draymonder/p/7966395.html

  • 相关阅读:
    function与感叹号
    js中的|| 与 &&
    [转] html屏蔽右键、禁止复制
    ExtJS 5.1 WINDOW BLUR
    ExtJS 网页版执行工具
    Excel 随即获得一组数据集中的数据
    [转] Spring Data JPA Tutorial: Pagination
    Set up eclipse for Ext js and spket IDE plugin
    ExtJS Alias, xtype and widget
    ExtJS stores
  • 原文地址:https://www.cnblogs.com/curo0119/p/8522482.html
Copyright © 2011-2022 走看看