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

【题目描述】
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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Antique Comedians of Malidinesia would like to play a new discovered comedy of Aristofanes. Putting it on a stage should be a big surprise for the audience so all the preparations must be kept absolutely secret. The ACM director suspects one of his competitors of reading his correspondece. To prevent other companies from revealing his secret, he decided to use a substitution cipher in all the letters mentioning the new play. Substitution cipher is defined by a substitution table assigning each character of the substitution alphabet another character of the same alphabet. The assignment is a bijection (to each character exactly one character is assigned -- not neccessary different). The director is afraid of disclosing the substitution table and therefore he changes it frequently. After each change he chooses a few words from a dictionary by random, encrypts them and sends them together with an encrypted message. The plain (i.e. non-encrypted) words are sent by a secure channel, not by mail. The recipient of the message can then compare plain and encrypted words and create a new substitution table. Unfortunately, one of the ACM cipher specialists have found that this system is sometimes insecure. Some messages can be decrypted by the rival company even without knowing the plain words. The reason is that when the director chooses the words from the dictionary and encrypts them, he never changes their order (the words in the dictionary are lexicographically sorted). String a1a2 ... ap is lexicografically smaller than b1b2 ... bq if there exists an integer i, i <= p, i <= q, such that aj=bj for each j, 1 <= j < i and ai < bi. The director is interested in which of his messages could be read by the rival company. You are to write a program to determine that. Input Output Sample Input 2 5 6 cebdbac cac ecd dca aba bac cedab 4 4 cca cad aac bca bdac Sample Output abcde Message cannot be decrypted.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值