hdu1535 spfa

RK3576+IMX415 MIPI摄像头零拷贝显示系统 MIPI CSI-2是嵌入式视觉系统中主流的高速图像传感器接口标准,其核心价值在于低延迟、高带宽与硬件级DMA直通能力。基于V4L2子系统与DRM/KMS驱动栈,可构建从传感器RAW数据到帧缓冲区的零拷贝通路,显著降低CPU负载并提升实时性。该技术广泛应用于工业检测、边缘AI推理前数据接入及多路同步采集等场景。本文以Rockchip RK3576 SoC和索尼IMX415传感器为典型组合,详解MIPI物理层适配、内核驱动集成、GStreamer零拷贝管道搭建及systemd服务化部署,覆盖从硬件信号完整性到 阅读详情

Invitation Cards

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1202    Accepted Submission(s): 520


Problem Description
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. 
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. 

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. 

 

Input
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. 
 

Output
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. 
 

Sample Input
  
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
 

Sample Output
  
46 210
 

Source
 

Recommend
LL
 
两次spfa+一次重新建图即可 
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define inf 99999999
using namespace std;
int first[1000005];
int next[1000005];
struct node
{
    int u,v,w;
};
node e[1000005];
bool inq[1000005];
int d[1000005];
int p;
int qq;
void spfa1(int u)
{
    int i;
    for(i=0;i<=p;i++)
        d[i]=inf;
    d[u]=0;
    memset(inq,0,sizeof(inq));
    queue<int> q;
    q.push(u);
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        inq[u]=false;
        int k;
        for(k=first[u];k!=-1;k=next[k])
        {
            int v=e[k].v;
            if(d[v]>d[u]+e[k].w)
            {
                d[v]=d[u]+e[k].w;
                if(!inq[v])
                {
                    inq[v]=true;
                    q.push(v);
                }
            }
        }
    }
}
void spfa2(int u)
{
    int i;
    for(i=0;i<=p;i++)
        d[i]=inf;
    d[u]=0;
    memset(inq,0,sizeof(inq));
    queue<int> q;
    q.push(u);
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        inq[u]=false;
        int k;
        for(k=first[u];k!=-1;k=next[k])
        {
            int v=e[k].u;
            if(d[v]>d[u]+e[k].w)
            {
                d[v]=d[u]+e[k].w;
                if(!inq[v])
                {
                    inq[v]=true;
                    q.push(v);
                }
            }
        }
    }
}
void build_map()
{
    int i;
    memset(next,-1,sizeof(next));
    memset(first,-1,sizeof(first));
    for(i=0;i<qq;i++)
    {
        int u=e[i].u;
        int v=e[i].v;
        next[i]=first[v];
        first[v]=i;
    }

}
int main()
{
    int t;
    scanf("%d",&t);
    int cas=0;
    for(cas=0;cas<t;cas++)
    {
        scanf("%d%d",&p,&qq);
        int i;
        memset(first,-1,sizeof(first));
        memset(next,-1,sizeof(next));
        for(i=0;i<qq;i++)
        {
            scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
            next[i]=first[e[i].u];
            first[e[i].u]=i;
        }
        spfa1(1);
        int sum=0;
        for(i=2;i<=p;i++)
            sum+=d[i];
        build_map();
        spfa2(1);
        for(i=2;i<=p;i++)
            sum+=d[i];
        printf("%d\n",sum);
    }
    return 0;
}


YonBIP 3.0 报表开发+报表超链接 用友报表开发 阅读详情

相关推荐

CentOS7下用FreeRADIUS+AD实现802.1X认证完整指南(附华为交换机配置)

本文提供了在CentOS 7系统上部署FreeRADIUS并与Windows Active Directory集成,以实现企业级802.1X网络认证的完整实战指南。内容涵盖从架构原理、服务器配置(包括Kerberos、Samba Winbind集成)、FreeRADIUS核心设置与AD联动,到华为交换机的详细配置步骤。重点解决了生产环境中常见的高可用、动态VLAN下发及深度排错问题,为企业构建集中、安全的网络准入控制体系提供了经过验证的解决方案。

weixin_29273849的博客 367

最短路dijkstra—Invitation Cards(POJ-1511)

题目链接:>_> 题目:Invitation Cards 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, m...

Darge. 282

Kaggle时间序列竞赛金牌方案解析与实战指南

本文深度解析了Kaggle时间序列竞赛的金牌方案,揭示了其成功不仅依赖先进模型,更在于系统工程思维。文章系统阐述了从数据理解、特征工程到模型集成与后处理的全流程,并重点剖析了分层建模、自定义损失函数、时序交叉验证等核心技巧,为参赛者提供了从理论到实战的完整指南。

weixin_29196315的博客 321

poj 3259 Bellman-ford + SPFA

Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 43809   Accepted: 16085 Description While exploring his many farms, Farmer John has discovered a

转角的守望 503

POJ 1511 邻接表+spfa

第一次用邻接表做题,第一次写spfa算法,,,。这道题就是用两次spfa,分别求正向图的最短路和反向图的最短路,结果相加就可以了。。题目: Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 13090   Accepted: 4240

1159

CSU-ACM2017暑期训练14-最短路 D - 输入量很大的模板题

D - 输入量很大的模板题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 Com

xiyue_jiang的博客 486

邻接表(邻接图)

1.题目引入: 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 nec

weixin_52914088的博客 196

SPFA邻接表】HDU 1535 Invitation Cards

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1535

F丶轩 580

hdu 1535 Invitation Cards(SPFA

hdu 1535 Invitation Cards 题意:就是一个人需要走很多

程序员的冷浪漫 911

HDU 1535 Invitation Cards (spfa, 链式前向星,逆向建图)

点击打HDU 1535 Invitation Cards 开链接 题意就是先算出从点1到其他点的最短路径长度,然后算出从其他各点到1的最短路径,最后求和。 算从其他各点到1的最短路径时应该先将图逆向存储,此时spfa算法也有差异,详见代码。 参考博客:点击打开链接 第一次学会链式前向星。。。感谢点击打开链接 #include #include #include

Benjamin_Z的博客 627

HDU - 1535 - Invitation Cards (spfa & 双向遍历)

HDU - 1535 - Invitation Cards 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 ...

Steve·Curcy 310

hdu1535 SPFA

题意:有n-1的站点和原点,然后原点有n-1个人

江上白衣凌云 602

hdu 1535 spfa

建个正向的图。 建个反向的图。 2遍spfa搞定。 #include #include #include #include #include using namespace std; int p,q; const int inf=0x3f3f3f3f; struct node { int v,nxt; int w; }edge[1000005]; struct s{

cnh294141800的专栏 799

HDU1535 (SPFA)

题目信息:点击打开链接 题解:题目大意:就是有一个原点,还有很多除原点外的点,保证原点可以到任何点,求原点到所有点再从所有点回到原点的最小距离。 我的思路:其实这就相当于两遍最短路,第一遍是原点到各个点,第二遍是各个点到原点,不能单纯的一遍最短路然后乘2,那就说明你真的很二,出题人有那么无聊吗?动脑子想想好不好。关于第二步各个点到原点,我们可以反向存图,再从原点往各个点跑一遍。 下面是代码:

Aiwen1413的博客 438

HDU1535 spfa

题意 给定一张图,计算从1到各点的最短距离+各点到1的最短距离。 spfa即可,分别正向,反向建一个图。 水~ View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<queue> 5 #i...

weixin_30263277的博客 108

hdu1535—Invitation Cards(spfa

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1535 Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 4143    Accepted S

zhiyuanjiang的博客 632

hdu1535spfa+邻接表

题目大意;有向图,求从1到i的距离和+i到1的距离和(最短) 思路:邻接表建图,正向一个,反向一个。spfa跑两遍即可。。 #include #include #include #include #include #include #include #include #include #include #include #include #include u

风一样的自由,色彩斑斓的雨季 281

HDU 1535 Invitation Cards SPFA

题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1535题意给定单向图,从1点走到其他任意一点,再返回n,直到所有点走完,求最短路。思路图是单向的,从1点跑最短路可以得到1到其他点的最短距离。反向建图从1点跑最短路可以得到其他点到1点的最短距离,边要先保存起来,正向跑完后销毁,建反向再跑一次。同时建正向和反向超内存。。#include<cstdio> #i

chen_minghui的博客 287

最短路,Dijkstra,SPFA——hdu1535

题目链接 今天集训学长没有给负环的题,所以一下子全都用Dijkstra做了,SPFA都没练习到,所以专门把这道不卡SPFA的题拿来练练 题目含义 求1到其他点的最短距离之和,加上其他点到1的最短距离之和 题目分析 求1到其他点的最短距离之和,也就是单源最短路径,Dijkstra和SPFA应该都行 而其他点到1的最短距离之和,实际上还是求的1到其他点的距离,不过由于路径两个方向...

weixin_30732487的博客 110

hdu 1535 Invitation Cards

点击打开链接hdu1535 思路:最短路+SPFA 分析: 1 题目要求的是总的最小的花费,意思就是要求每一个人的花费都最小。 2 由于每一个人都是从1出去,最后还是都要回到1的,那么求解的时候就要分成两部分“出去+回来”;出去的话直接利用SPFA(1),1作为起点即可求出每一点的最小花费,回来的话如果是直接利用对每一个人进行SPFA,那么这样肯定超时。仔细想想要求的是每一个点到1的最...

我是传奇 256

Invitation Cards HDU - 1535 SPFA

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 ...

weixin_41544329的博客 147

hdu 1317+hdu 1535(SPFA)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1317 思路:只要在SPFA中将一个条件,就不会进入负环。那么如果有正环呢,显然退出条件是某个点入队列次数>=n,此时退出时只需判断当前点是否与n存在路径,这步可以用Floyd来实现。。。 View Code 1 #include 2 #include 3 const int MA

几百个教授的专栏 499

七自由度simulink车辆模型

用simulink搭建整车七自由度模型,包括整车垂向,俯仰 侧倾

基于STM32单片机城市消防无人机控制系统的设计

1、18000字论文,查重25%以下;2、STM32 单片机最小系统 无线通信电路 电池管理电路 地面无线数据接收器 OLED 显示电路 声光报警电路 无线图像传输模块 GPS 定位模块 机载视频监控器3、系统软件部分设计 软件通信协议 机载控制器的软件设计 地面操控终端的软件设计 人机交互界面的设计 软件功能设计

上一篇: 最短路径 之 SPFA算法
下一篇: hdu1546 dijkstra
JustSteps
博客等级 码龄14年 48粉丝 210原创
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值