题目:http://poj.org/problem?id=1135

只是求以1为起点的最短路罢了。稍稍判断一下在边上的情况。

多亏提醒:毒数据——n==1!一定要dis [ k ] >= ans!!!

注意输出格式(换行)。

#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int n,m,head[],xnt,x,y,T;
int hp[],cnt,k1,k2;
ll dis[],z;
double ans;
bool vis[];
struct Edge{
int next,to;
ll w;
Edge(int a=,int b=,ll c=):next(a),to(b),w(c) {}
}edge[];
ll abss(ll k)
{
if(k<)k=-k;
return k;
}
void push(int k)
{
hp[++cnt]=k;
int now=cnt;
while(now>)
{
int tp=(now>>);
if(dis[hp[now]]<dis[hp[tp]])swap(hp[now],hp[tp]);
else break;
now=tp;
}
}
int del()
{
int res=hp[];
hp[]=hp[cnt--];
int now=;
while((now<<)<=cnt)
{
int tp=(now<<);
if(tp<cnt&&dis[hp[tp+]]<dis[hp[tp]])tp++;
if(dis[hp[tp]]<dis[hp[now]])swap(hp[tp],hp[now]);
else break;
now=tp;
}
return res;
}
int main()
{
while(++T)
{
scanf("%d%d",&n,&m);
if(!n&&!m)return ;
memset(dis,,sizeof dis);
memset(head,,sizeof head);
memset(vis,,sizeof vis);
xnt=;ans=;k1=;k2=;
for(int i=;i<=m;i++)
{
scanf("%d%d%lld",&x,&y,&z);
edge[++xnt]=Edge(head[x],y,z);head[x]=xnt;
edge[++xnt]=Edge(head[y],x,z);head[y]=xnt;
}
dis[]=;push();
while(cnt)
{
int k=del();
while(cnt&&vis[k])k=del();
if(vis[k])break;
vis[k]=;
if(dis[k]>=ans)//////////
{
ans=dis[k];k1=k;
}
for(int i=head[k],v;i;i=edge[i].next)
if(!vis[v=edge[i].to]&&dis[k]+edge[i].w<dis[v])
{
dis[v]=dis[k]+edge[i].w;
push(v);
}
}
double c=;
for(int i=;i<=n;i++)
for(int j=head[i],v;j;j=edge[j].next)
if(abss(dis[i]-dis[v=edge[j].to])<edge[j].w&&
(c=max(dis[i],dis[v])+(double)(edge[j].w-abss(dis[i]-dis[v]))/)>ans)
{
ans=c;k1=min(i,v);k2=max(i,v);
}
printf("System #%d\n",T);
if(!k2)
printf("The last domino falls after %.1lf seconds, at key domino %d.\n\n",ans,k1);
else
printf("The last domino falls after %.1lf seconds, between key dominoes %d and %d.\n\n",ans,k1,k2);
}
}

POJ1135 Domino Effect的更多相关文章

  1. POJ1135 Domino Effect(SPFA)

    题目大概是,普通骨牌连接两张关键骨牌,一旦一张关键骨牌倒下与其相邻的普通骨牌也倒下,普通骨牌倒下与其相邻的骨牌也倒下.给出所有有普通骨牌相连的两个关键骨牌之间普通骨牌倒下所需时间,问1号关键骨牌开始倒 ...

  2. [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  3. CF 405B Domino Effect(想法题)

    题目链接: 传送门 Domino Effect time limit per test:1 second     memory limit per test:256 megabytes Descrip ...

  4. POJ 1135 Domino Effect(Dijkstra)

    点我看题目 题意 : 一个新的多米诺骨牌游戏,就是这个多米诺骨中有许多关键牌,他们之间由一行普通的骨牌相连接,当一张关键牌倒下的时候,连接这个关键牌的每一行都会倒下,当倒下的行到达没有倒下的关键牌时, ...

  5. POJ 1135 Domino Effect (spfa + 枚举)- from lanshui_Yang

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  6. UVA211-The Domino Effect(dfs)

    Problem UVA211-The Domino Effect Accept:536  Submit:2504 Time Limit: 3000 mSec  Problem Description ...

  7. POJ 1135 Domino Effect (Dijkstra 最短路)

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9335   Accepted: 2325 Des ...

  8. POJ 1135.Domino Effect Dijkastra算法

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10325   Accepted: 2560 De ...

  9. zoj 1298 Domino Effect (最短路径)

    Domino Effect Time Limit: 2 Seconds      Memory Limit: 65536 KB Did you know that you can use domino ...

随机推荐

  1. [Leetcode] Unique binary search trees 唯一二叉搜索树

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  2. POJ 2488 DFS

    DES:给一个n行m列的棋盘.马以L型走.问能否从某一位置开始走完棋盘上的每个位置.若能继续输出字典序最小的一条路径. 很典型的dfs.搜的时候就按照字典序从小到大的顺序.搜到第一条路径时停止搜索输出 ...

  3. 51nod1671

    题解: 这一题感觉和noip2015d2t3一模一样,而且是弱化版 但是,后来发现貌似每两个点都可以建立虫洞 好在是i和i+1有边,所以就直接用二分+贪心了 代码: #include<bits/ ...

  4. 去除字符串中的emoji字符

    对于使用utf8编码的mysql数据库来说,如果字符串中存在emoji小图像,是不能存进数据库中的,查了一下,原因大概是因为utf8编码可以存1-3个字节的字符,但是emoji是4个字节:解决方法可以 ...

  5. docker中进行IDA远程调试提示“TRACEME: Operation not permitted[1] Closing connection from 192.168.109.1...”的解决方法

    加入 --security-opt seccomp:unconfined选项,关闭docker远程命令执行保护 如: docker run --security-opt seccomp:unconfi ...

  6. ES6.0 Generator 三种用法

    // Generator start ------- thunk 用法 const Thunk = function(fn) { return function (...args) { return ...

  7. 强化学习 平台 openAI 的 gym 安装 (Ubuntu环境下如何安装Python的gym模块)

    openAI 公司给出了一个集成较多环境的强化学习平台  gym , 本篇博客主要是讲它怎么安装. openAI公司的主页: https://www.openai.com/systems/ 从主页上我 ...

  8. spark中saveAsTextFile如何最终生成一个文件

    原文地址: http://www.cnblogs.com/029zz010buct/p/4685173.html 一般而言,saveAsTextFile会按照执行task的多少生成多少个文件,比如pa ...

  9. CodeForces - 285E: Positions in Permutations(DP+组合数+容斥)

    Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive in ...

  10. Future接口和FutureTask类【FutureTask实现了Runnable和Future接口】

    Future API: public interface Future<V> { /** * Attempts to cancel execution of this task. This ...