POJ 1511
来源:互联网 发布:通达信布林线指标源码 编辑:程序博客网 时间:2024/05/21 00:45
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>using namespace std;#define N 1000000+100#define inf 1000000000+10typedef long long ll;struct Edge{ int to,v; int next;}edge1[N],edge2[N];int head1[N],head2[N],book[N],strk[N];ll go[N],backk[N];ll spfa(Edge *edge,ll *go,int *head,int n);void Insert(Edge *edge,int *head,int a,int b,int v,int i);int main(){ int n,m,i,j,k,t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(head1,-1,(n+10)*sizeof(n)); memset(head2,-1,(n+10)*sizeof(n)); int a,b,v; for(i=1; i<=m; i++) { scanf("%d%d%d",&a,&b,&v); Insert(edge1,head1,a,b,v,i); Insert(edge2,head2,b,a,v,i); } for(i=1; i<=n; i++) go[i] = inf , backk[i] = inf; printf("%lld\n",spfa(edge1,go,head1,n)+spfa(edge2,backk,head2,n)); }}void Insert(Edge *edge,int *head,int a,int b,int v,int i){ edge[i].to = b; edge[i].v = v; edge[i].next = head[a]; head[a] = i;}ll spfa(Edge *edge,ll *go,int *head,int n){ memset(book,0,sizeof(book)); go[1] = 0 , book[1] = 1; int top = 0; strk[++top] = 1; while(top) { int u = strk[top--]; book[u] = 0; int t = head[u]; while(t != -1) { int a = edge[t].to; int v = edge[t].v; if(go[a] > go[u] + v) { go[a] = go[u] + v; if(book[a] == 0) book[a] = 1 , strk[++top] = a; } t = edge[t].next; } } ll sum = 0; for(int i=1; i<=n; i++) sum += go[i]; return sum;}
先在这存着,内容以后再补。
0 0
- poj 1511
- POJ 1511
- poj 1511
- POJ 1511
- POJ 1511
- POJ 1511
- poj 1511
- POJ 1511
- poj---1511
- POJ 1511
- poj 1511
- POJ 1511
- poj 1511
- POJ 1511 Invitation Cards
- poj 1511 Invitation Cards
- poj 1511 Invitation Cards
- POJ 1511 Invitation Cards
- poj 1511 spfa
- shell stdin 变 参数
- 【bzoj3572】 世界树
- 不平衡数据下的机器学习方法简介
- linux 重命名 rename
- postfix 扣下退信
- POJ 1511
- Android触控基础:MotionEvent
- js实现新闻列表自动滚动
- linux java 线上问题排查
- 有限状态机
- java知识整理
- 正则表达式 元字符备查
- 记录org.springframework.web.client.RestTemplate的用法
- 正则表达式优化