ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[kuangbin]专题四 最短路练习 Invitation Cards POJ - 1511【dijkstra】

2019-08-31 20:36:16  阅读:257  来源: 互联网

标签:Node 10 int stop dijkstra cost POJ kuangbin MAXN


【题目描述】
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer has assigned exactly one bus stop and he or she stays there the whole day and gives invitation to people travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing and robbery.
在电视时代,参加戏剧表演的人并不多。 Malidinesia的古董喜剧演员都知道这个事实。他们想传播戏剧,最重要的是传播古董喜剧。他们已经打印了包含所有必要信息和计划的邀请卡。雇用了很多学生在人们中间分发这些邀请。每个学生志愿者都指定了一个公共汽车站,他或她整天呆在那里,并邀请乘坐公共汽车的人。学生们学习如何影响人们以及影响和抢劫之间的区别是一个特殊的课程。
The transport system is very special: all lines are unidirectional and connect exactly two stops. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g. X:00 or X:30, where ‘X’ denotes the hour. The fee for transport between two stops is given by special tables and is payable on the spot. The lines are planned in such a way, that each round trip (i.e. a journey starting and finishing at the same stop) passes through a Central Checkpoint Stop (CCS) where each passenger has to pass a thorough check including body scan.
传输系统非常特殊:所有线路都是单向的,并且恰好连接两个站点。公共汽车每半小时从出发站出发。在到达目的地站点后,他们返回到原始站点,在那里他们等到下一个完整的半小时,例如, X:00或X:30,其中“X”表示小时。两站之间的运输费用由特殊表格提供,并在现场支付。这些线路以这样的方式进行规划,即每次往返(即在同一站点开始和结束的旅程)经过中央检查站(CCS),每个乘客必须通过彻底检查,包括身体扫描。
All the ACM student members leave the CCS each morning. Each volunteer is to move to one predetermined stop to invite passengers. There are as many volunteers as stops. At the end of the day, all students travel back to CCS. You are to write a computer program that helps ACM to minimize the amount of money to pay every day for the transport of their employees.
所有ACM学生会员每天早上都会离开CCS。每个志愿者将移动到一个预定的站点以邀请乘客。有许多志愿者作为站点。在一天结束时,所有学生都会回到CCS。您将编写一个计算机程序,帮助ACM最大限度地减少每天为员工运输所支付的金额。

【输入】
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there are Q lines, each describing one bus line. Each of the lines contains exactly three numbers - the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices are positive integers the sum of which is smaller than 1000000000. You can also assume it is always possible to get from any stop to any other stop.
输入由N个案例组成。 输入的第一行只包含正整数N.然后按照这些情况进行操作。 每种情况都以一条恰好包含两个整数P和Q的行开始,1 <= P,Q <= 1000000.P是包括CCS的停止数,Q是总线数。 然后有Q行,每行描述一条总线。 每行包含三个数字 - 原始站,目的站和价格。 CCS由数字1指定。价格是正整数,其总和小于1000000000.您还可以假设始终可以从任何站到任何其他站。

【输出】
For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.
对于每个案例,打印一行,其中包含ACM每天要支付的最低金额,用于其志愿者的旅行费用。

【样例输入】
2
2 2
1 2 13
2 1 33
4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50

【样例输出】
46
210

题目链接:https://cn.vjudge.net/problem/POJ-1511

和POJ3268没什么区别
POJ什么时候能换判题机啊。。。cin过不了,scanf能过

代码如下:

#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
static const int MAXN=1000000;
int x[MAXN+10],y[MAXN+10],z[MAXN+10];
struct Node{
    int v,c;
    Node(int _v=0,int _c=0):v(_v),c(_c){}
    bool operator < (const Node &r) const {
        return c>r.c;
    }
};
struct Edge{
    int v,cost;
    Edge(int _v=0,int _cost=0):v(_v),cost(_cost){}
};
vector<Edge> E[MAXN+10];
bool vis[MAXN+10];
int dist[MAXN+10];
void dijkstra(int n,int start)
{
    for(int i=1;i<=n;i++)
    {
        vis[i]=false;
        dist[i]=INF;
    }
    priority_queue<Node> Q;
    dist[start]=0;
    Q.push(Node(start,0));
    while(!Q.empty())
    {
        Node tmp=Q.top();
        Q.pop();
        int u=tmp.v;
        if(vis[u])
            continue;
        vis[u]=true;
        for(int i=0;i<E[u].size();i++)
        {
            int v=E[u][i].v;
            int cost=E[u][i].cost;
            if(!vis[v] && dist[v]>dist[u]+cost)
            {
                dist[v]=dist[u]+cost;
                Q.push(Node(v,dist[v]));
            }
        }
    }
}
int main()
{
    // std::ios::sync_with_stdio(false);
    // std::cin.tie(0),cout.tie(0);
    int T;
    // cin>>T;
    scanf("%d",&T);
    while(T--)
    {
        int p,q;
        // cin>>p>>q;
        scanf("%d%d",&p,&q);
        for(int i=1;i<=p;i++)
            E[i].clear();
        for(int i=1;i<=q;i++)
        {
            // cin>>x[i]>>y[i]>>z[i];
            scanf("%d%d%d",&x[i],&y[i],&z[i]);
            E[x[i]].push_back(Edge(y[i],z[i]));
        }
        dijkstra(p,1);
        long long ans=0;
        for(int i=1;i<=p;i++)
            ans+=dist[i];
        for(int i=1;i<=p;i++)
            E[i].clear();
        for(int i=1;i<=q;i++)
            E[y[i]].push_back(Edge(x[i],z[i]));
        dijkstra(p,1);
        for(int i=1;i<=p;i++)
            ans+=dist[i];
        // cout<<ans<<endl;
        printf("%lld\n",ans);
    }
    return 0;
}

标签:Node,10,int,stop,dijkstra,cost,POJ,kuangbin,MAXN
来源: https://blog.csdn.net/inv00ker/article/details/100176485

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有