题意:略
思路:略

#include<bits/stdc++.h>
using namespace std;
#define maxn 1010
#define INF 0x3f3f3f3f3f3f
typedef long long ll;
struct Edge{ll to,nxt,w;
}edge[maxn<<2];
ll tot=0,cnt=0,head[maxn],vis[maxn];
void add(ll u,ll v,ll w){edge[++tot].to=v; edge[tot].nxt=head[u]; edge[tot].w=w; head[u]=tot;
}
ll n,m,s,t,inq[maxn],dis[maxn],pre[maxn],path[maxn],mp[maxn][maxn];
ll spfa(int u){memset(dis,INF,sizeof(dis));memset(inq, 0 ,sizeof(inq));queue<int>q;q.push(u);inq[u]=1;dis[u]=0;while(!q.empty()){int t=q.front();q.pop(); inq[t]=0;for(int i=head[t];~i;i=edge[i].nxt){Edge e=edge[i];if(dis[e.to]>dis[t]+e.w){pre[e.to]=t;dis[e.to]=dis[t]+e.w;if(!inq[e.to]){inq[e.to]=1;q.push(e.to);}}} }return dis[s];
}
void print(int s){if(pre[s]!=-1) print(pre[s]);path[cnt++]=pre[s];
}
int main(){int T; scanf("%d",&T);while(T--){memset(mp,0,sizeof(mp));memset(head,-1,sizeof(head));scanf("%lld%lld",&n,&m);for(int i=1;i<=m;i++){ll u,v,w; scanf("%lld%lld%lld",&u,&v,&w);add(u,v,w); mp[u][v]=w;}for(int i=1;i<=6;i++){memset(pre,-1,sizeof(pre));scanf("%lld%lld",&s,&t);printf("%lld\n",-spfa(t));cnt=0;print(s); path[cnt]=s;for(int i=cnt-1;i>=1;i--){add(path[i+1],path[i],-mp[path[i]][path[i+1]]);mp[path[i+1]][path[i]]=-mp[path[i]][path[i+1]];}}}return 0;
}

Holy Grail【spfa签到题】相关推荐

  1. [ICPC Asia Nanjing 2019] Holy Grail (spfa最短路)

    题意:给出一个n个点,m条边的有向图,再给6组询问,在u,v间建一条权值最小的边,使图中没有负环.保证有解. 做法:u,v加边,如果有负环必定过u,v.以v为起点,到u的最短路和u->v组成的环 ...

  2. 2019ACM南京网络赛 Holy Grail

    ACM2019南京网络赛 Holy Grail SPFA 或 Bellman-Ford模板题(存在负权路径) Description Input Output 样例输入 样例输出 题目链接: http ...

  3. 【2019icpc南京站网络赛 - H】Holy Grail(最短路,spfa判负环)

    题干: As the current heir of a wizarding family with a long history,unfortunately, you find yourself f ...

  4. H - Holy Grail

    H - Holy Grail 题意: 题干又臭又长 我简单说说 n个点,m条有向边,边权为负,然后给你六组起始点(s点和t点),你要在s和t之间建一个有向边,要使得权值最小,问这六组边依次是多少? 不 ...

  5. Holy Grail

    Holy Grail 限制1000 ms 256 MB As the current heir of a wizarding family with a long history,unfortunat ...

  6. H. Holy Grail(The Preliminary Contest for ICPC Asia Nanjing 2019题解)

    题目链接 As the current heir of a wizarding family with a long history,unfortunately, you find yourself ...

  7. CTF-练习平台-WEB之 签到题

    一.签到题 根据提示直接加群在群公告里就能找到~ 转载于:https://www.cnblogs.com/Yuuki-/p/8075945.html

  8. 牛客小白月赛16 小石的签到题(博弈)

    牛客小白月赛16 小石的签到题 链接:https://ac.nowcoder.com/acm/contest/949/A来源:牛客网 题目描述 输入描述: 共一行,输入一个数 nnn . 输出描述: ...

  9. 【牛客 - 370A】签到题(线段树扫描线 或 STLset)(求线段并)

    题干: 链接:https://ac.nowcoder.com/acm/contest/370/A 来源:牛客网 恭喜你找到了本场比赛的签到题! 为了让大家都有抽奖的机会,只需要复制粘贴以下代码(并且稍 ...

最新文章

  1. 【转载】MongoDB安装并随windows开机自启
  2. CentOS7中怎样修改主机名和hosts文件(配置IP和主机名的对应管理)
  3. 【POJ - 1028】 Web Navigation( 栈 or 模拟队列 )
  4. Node.js路径操作
  5. debian 10 Buster正式发布了
  6. java基础七--网络编程(1)
  7. egret 白鹭引擎学习笔记-写在前面的话
  8. 美国散户从90%降到6%,他们是如何被“消灭”的?
  9. java 第十一章 多线程技术
  10. 2021年安全员-C证(陕西省)考试资料及安全员-C证(陕西省)免费试题
  11. asp.net1050-消防车辆维修保养辅助系统#毕业设计
  12. 微信小程序信息授权获取(头像,昵称,等)
  13. 版权和商标权有什么关系?版权和商标的区别在哪里?
  14. C/C++内存泄漏和野指针的区别
  15. Spring Security学习 详细
  16. Android Studio最完整的插件整理
  17. python爬取网站四种姿势_python爬取网站数据四种姿势,你值得拥有~
  18. 实例:用C#.NET手把手教你做微信公众号开发(4)--获取普通access_token、jsapi的方法;用MediaId获取微信服务器图片
  19. 开源私有云盘python_搭建个人/企业私有云盘-seafile
  20. Linux下rpmbuild命令的使用

热门文章

  1. android集成环信客服云_2019.6.12
  2. 简单通过微信公众号获取OPEN ID
  3. 采用MPI_Send 和MPI_Recv 编写代码来实现包括MPI_Bcast、MPI_Alltoall、MPI_Gather、MPI_Scatter 等MPI 群集通信函数的功能
  4. 二级路由器配置网址无法访问的解决方法
  5. 编程计算: 1!+3!+5!+...+(2n-1)!,要求阶乘计算调用fun函数实现, 数据输入及打印结果在主函数实现。阶乘计算fun函数原型为: long fun(int m); CQUPT题库
  6. apache rewrite规则全攻略
  7. ICP经营许可证与ICP备案有什么区别?
  8. 恺撒密码算法 Java实现
  9. 关于滚动条内子控件控制问题
  10. word2016 卡顿_word2016经常发生卡顿现象