J - Invitation Cards
Malidinesia知道这个事实。他们想传播戏剧尤其是古老的戏剧,他们在邀请卡上打印必要的信息和一些节目,一些学生被雇佣过来发传单,每个学生志愿者都被分配一个公共汽车站来发传单,一个特殊的课程教会了学生们如何影响别人。
#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的更多相关文章
- J - Invitation Cards 最短路
In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...
- D - Silver Cow Party J - Invitation Cards 最短路
http://poj.org/problem?id=3268 题目思路: 直接进行暴力,就是先求出举行party的地方到每一个地方的最短路,然后再求以每一个点为源点跑的最短路. 还有一种方法会快很多, ...
- POJ 1511 Invitation Cards (spfa的邻接表)
Invitation Cards Time Limit : 16000/8000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) ...
- POJ 1511 Invitation Cards (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- HDU1535——Invitation Cards(最短路径:SPAF算法+dijkstra算法)
Invitation Cards DescriptionIn the age of television, not many people attend theater performances. A ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
- hdu 1535 Invitation Cards(SPFA)
Invitation Cards Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) T ...
- SPFA算法(2) POJ 1511 Invitation Cards
原题: Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 31230 Accepted: ...
- 图论trainning-part-1 E. Invitation Cards
E. Invitation Cards Time Limit: 8000ms Memory Limit: 262144KB 64-bit integer IO format: %lld Ja ...
随机推荐
- PHP 一维数组排序
一.按照键值从低到高排序,并赋予新的键名 1 函数:sort( array &array[, int sort_flags]) 2 参数: (1)&array : 要排序的一维数组, ...
- mem 族函数的实现
1.void * memcpy ( void * dest, const void * src, size_t num ); 头文件:#include <string.h>memcpy() ...
- 【HDU4366】【DFS序+分块】Successor
Problem Description Sean owns a company and he is the BOSS.The other Staff has one Superior.every st ...
- Java学习----到底调用哪一个方法(多态)
public class Father { public void print() { System.out.println("Father:print()"); } } publ ...
- ng的数据绑定
ng创建了一个自己的事件循环,当浏览器事件(常用的dom事件,xhr事件等)发生时,对DOM对应的数据进行检查,若更改了,则标记为脏值,并进入更新循环,修改对应的(可能是多个) DOM的参数.这样就实 ...
- Java字符串学习
Java中字符串是String类的实例,字符串也是对象,所以 Java将字符串作为对象进行管理 Java使用java.lang 包中的String类来创建字符串. 1.定义字符串: 使用 " ...
- php判断手机移动设备访问
<?php function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROF ...
- web字体格式转换
@font-face { font-family: 'emotion'; src: url('emotion.eot'); /* IE9*/ src: url('emotion.eot?#iefix' ...
- CSS3的appearance属性--改变元素的外观
CSS3 appearance 属性 CSS 参考手册 实例 使 div 元素看上去像一个按钮: div { appearance:button; -moz-appearance:button; /* ...
- C# 进销存系统开发框架
C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4.0.htm 视频下载: 百度 ...