题目大意:邀请卡
在电视的时代,没有多少人会去剧院观看演出。古老的喜剧演员

Malidinesia知道这个事实。他们想传播戏剧尤其是古老的戏剧,他们在邀请卡上打印必要的信息和一些节目,一些学生被雇佣过来发传单,每个学生志愿者都被分配一个公共汽车站来发传单,一个特殊的课程教会了学生们如何影响别人。

这个运输系统(公路)非常的特别:所有的线路都是单向的,并且恰好都有两个站点相连(就是说没有交叉的路,因为交叉的地方都变成了站点),汽车从起点载着旅客出发然后到达目的地后空车返回用半个小时??(是到达用半个小时还是来回....),然后他们在那里等待下一个完整的半小时,两站之间现场付款,,,,(废话太多了,不翻译了,直接看数据)。
就是说这帮人现在一个叫做ccs(默认1号站)的地方集合然后乘坐公交车到达每一个车站,然后晚上从车站回来,求最少的总花费......跟那个D一模一样,题目一大堆废话。。。。。。。。。。。。。。
不过pq的范围很恐怖。。1百万,,什么城市有这么多车站。。。。我去
/////////////////////////////////////////////////////////////////////////
我小瞧了这道题,卡时间卡的特别厉害,而且还需要用long long,vector效率是非常低的,决定放弃vector,使用数组模拟链表
#include<algorithm>
#include<stack>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<string>
#include<map>
#include<iostream>
using namespace std; const int maxn = ;
const int oo = 0x3fffffff; struct BusStation
{
    int u, v, nextBus;
    long long pay;
}ege[maxn], data[maxn]; int head[maxn];
long long dis[maxn];
bool use[maxn]; void Add(int u, int v, long long w, int k)
{
    data[k].u = u;
    data[k].v = v;
    data[k].pay = w;
    data[k].nextBus = head[u];
    head[u] = k;
} long long spfa(int N)
{
    stack<int> Q;
    Q.push();
    use[] = true;     for(int i=; i<=N; i++)
        dis[i] = oo;
    dis[] = ;     while(Q.size())
    {
        int i = Q.top();Q.pop();
        use[i] = false;         for(int j=head[i]; j != ; j = data[j].nextBus)
        {
            int u = data[j].u, v = data[j].v;
            int pay = data[j].pay;             if(dis[u]+pay < dis[v])
            {
                dis[v] = dis[u] + pay;                 if(use[v] == false)
                {
                    Q.push(v);
                    use[v] = true;
                }
            }
        }
    }     long long sum=;     for(int i=; i<=N; i++)
        sum += dis[i];     return sum;
} int main()
{
    int T;     scanf("%d", &T);     while(T--)
    {
        int i, N, M;         scanf("%d%d", &N, &M);         memset(head, , sizeof(head));
        for(i=; i<=M; i++)
        {
            scanf("%d%d%lld", &ege[i].u, &ege[i].v, &ege[i].pay);
            Add(ege[i].u, ege[i].v, ege[i].pay, i);
        }         long long sumPay;         sumPay =  spfa(N);         memset(head, , sizeof(head));
        for(i=; i<=M; i++)
            Add(ege[i].v, ege[i].u, ege[i].pay, i);         sumPay += spfa(N);         printf("%lld\n", sumPay);
    }     return ;

}

J - Invitation Cards的更多相关文章

  1. J - Invitation Cards 最短路

    In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...

  2. D - Silver Cow Party J - Invitation Cards 最短路

    http://poj.org/problem?id=3268 题目思路: 直接进行暴力,就是先求出举行party的地方到每一个地方的最短路,然后再求以每一个点为源点跑的最短路. 还有一种方法会快很多, ...

  3. POJ 1511 Invitation Cards (spfa的邻接表)

    Invitation Cards Time Limit : 16000/8000ms (Java/Other)   Memory Limit : 524288/262144K (Java/Other) ...

  4. POJ 1511 Invitation Cards (最短路spfa)

    Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...

  5. HDU1535——Invitation Cards(最短路径:SPAF算法+dijkstra算法)

    Invitation Cards DescriptionIn the age of television, not many people attend theater performances. A ...

  6. [POJ] 1511 Invitation Cards

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 18198   Accepted: 596 ...

  7. hdu 1535 Invitation Cards(SPFA)

    Invitation Cards Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) T ...

  8. SPFA算法(2) POJ 1511 Invitation Cards

    原题: Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 31230   Accepted: ...

  9. 图论trainning-part-1 E. Invitation Cards

    E. Invitation Cards Time Limit: 8000ms Memory Limit: 262144KB 64-bit integer IO format: %lld      Ja ...

随机推荐

  1. Missing artifact com.sun:tools:jar:1.5.0

    http://java-suddy.iteye.com/blog/1821871(解决了我的问题)

  2. 【转】iOS开发UI篇—程序启动原理和UIApplication

    原文 http://www.cnblogs.com/wendingding/p/3766347.html   一.UIApplication 1.简单介绍 (1)UIApplication对象是应用程 ...

  3. 内联式css样式,直接写在现有的HTML标签中

    CSS样式可以写在哪些地方呢?从CSS 样式代码插入的形式来看基本可以分为以下3种:内联式.嵌入式和外部式三种.这一小节先来讲解内联式. 内联式css样式表就是把css代码直接写在现有的HTML标签中 ...

  4. Objective - C 中NSString (字符串)与C中的字符串转换问题

    NSString是一个常用的类,NSString是原生支持unicode C中的字符串 比如char * a = "hello world";  是utf8类型的, char* d ...

  5. 《Python 二三事》——python学习必看(转载)

        面向初学者介绍Python相关的一些工具,以及可能遇到的常见问题. 原文出处 原文作者:八八年出生的男性,互联网上常用id是 jagttt .目前正从事 IT 行业的工作.业余爱好是动漫游加电 ...

  6. window 配置 sendmail

    从http://glob.com.au/sendmail/下载sendmail.zip 解压sendmail.zip到目录下(最好使用短路径,长路径会导致问题的出现),我安装的路径是: E:\wamp ...

  7. Java常量和变量

    1.Java运行原理 编译+解释型语言: 程序代码经编译后转换为一种称为java字节码(.class文件)的中间语言 file.java--->Class.class java虚拟机JVM将字节 ...

  8. ARM的BIN文件反汇编方法

    最近在调试uboot的代码时,用的新版本的uboot,lowlevel_init函数里是空的,而且在链接文件中也没有发现对lowlevel_init.o的链接.在bl lowlevel_init 之前 ...

  9. php开发环境安装配置(1)

    个人记录高手请勿喷! 下载xampp我这是个中文版的可以自己搜索下载安装别的版本也行. 双击下载的xampp会提示路径相当于解压到指定的路径 到对应路径去可看到如下: 打开 2.配置: 成功之后会如下 ...

  10. api1

    http://www.android-doc.com/reference/android/app/Fragment.html