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

题目分类:图论

题意:n个顶点,然后给出从i到j的最短路径长度,求至少需要哪些边

第二组样例

第三组样例:

题目分析:

判断 a[i][j]==a[i][k]+a[k][j](详看代码)

代码:

#include<bits/stdc++.h>

using namespace std;

int a[][];

int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif int t,n;
scanf("%d",&t);
for(int kase=;kase<=t;kase++)
{
scanf("%d",&n);
memset(a,,sizeof(a));
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
bool ok=;
int ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
for(int k=;k<=n;k++)
{
if(i==k||k==j||i==j)
continue;
if(a[i][j]>a[i][k]+a[k][j])
{
ok=;
goto here;
}
else if(a[i][j]==a[i][k]+a[k][j])
{
//printf("%d %d\n",i,j);
ans++;
break;
}
}
}
}
here:
printf("Case %d: ",kase);
if(ok) printf("impossible\n");
else printf("%d\n",n*n-n-ans); } return ;
}

hdu 4034 Graph的更多相关文章

  1. HDU 4034 Graph(Floyd变形——逆向判断)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4034 Problem Description Everyone knows how to calcu ...

  2. HDU 4034 Graph Floyd最短路

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4034 题意: 给你一个最短路的表,让你还原整个图,并使得边最少 题解: 这样想..这个表示通过floy ...

  3. HDU 4034 Graph:反向floyd

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4034 题意: 有一个有向图,n个节点.给出两两节点之间的最短路长度,问你原图至少有多少条边. 如果无解 ...

  4. hdu 4034 Graph (floyd的深入理解)

    Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submi ...

  5. HDU 4034 Graph(floyd,最短路,简单)

    题目 一道简单的倒着的floyd. 具体可看代码,代码可简化,你有兴趣可以简化一下,就是把那个Dijsktra所实现的功能放到倒着的floyd里面去. #include<stdio.h> ...

  6. hdu 4034 Graph floyd

    题目链接 给出一个有向图各个点之间的最短距离, 求出这个有向图最少有几条边, 如果无法构成图, 输出impossible. folyd跑一遍, 如果dp[i][j] == dp[i][k]+dp[k] ...

  7. hdu 4034 Graph(逆向floyd)

    floyd的松弛部分是 g[i][j] = min(g[i][j], g[i][k] + g[k][j]);也就是说,g[i][j] <= g[i][k] + g[k][j] (存在i-> ...

  8. [la P5031&hdu P3726] Graph and Queries

    [la P5031&hdu P3726] Graph and Queries Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: ...

  9. HDU 3726 Graph and Queries treap树

    题目来源:HDU 3726 Graph and Queries 题意:见白书 思路:刚学treap 參考白皮书 #include <cstdio> #include <cstring ...

随机推荐

  1. oracle事务和锁(转)

    If you use a SET TRANSACTION statement, then it must be the first statement in your transaction. How ...

  2. 基于visual Studio2013解决C语言竞赛题之0611素数排序

       题目

  3. 使用Xshell生成key,避免password登录linux

    我们通常Xshell使用命令ssh user@ip远程登录linux,这将促使我们进入password更麻烦的,通缉免费password日志的话,我们可以生成相应的key.然后把遥控器server上, ...

  4. IOS学习之segmented control

    转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/27086877 作者:小马 什么是segmented control? 先上几张图: ...

  5. Java 生成本文文件的时候,Dos格式转成Unix格式

    仅仅须要在生成文本的最后 加上 sb.append("\n\r");就可以 是/n/r 不是/r/n

  6. 在 Visual Studio 调试器中指定符号 (.pdb) 和源文件

    查找并指定符号文件和源文件:指定符号加载行为.使用符号和源服务器上:加载符号自动或在要求.   内容 查找符号 (.pdb) 文件 查找源文件   查找符号 (.pdb) 文件 说明 在之前的 Vis ...

  7. Determine whether an integer is a palindrome. Do this without extra space.

    看到这个题目的时候,首先不认识 Determine这个单词.英文不好没办法,查了下是确认的意思,然后不懂 palindrome这个单词, 查了下是回文的意思. 问题是 回文是个什么东西,官方解释: A ...

  8. 用xerces-c来进行xml schema校验

    在xerces-c的官方站点上有文章指引说明是怎样进行xml schema校验. http://xerces.apache.org/xerces-c/schema-3.html 给出的样例代码: // ...

  9. 4Sum -- LeetCode

    原题链接: http://oj.leetcode.com/problems/4sum/  这道题要求跟3Sum差点儿相同,仅仅是需求扩展到四个的数字的和了.我们还是能够依照3Sum中的解法,仅仅是在外 ...

  10. Android反编译-逆天的反编译

    Jar包的反编译: Java的世界是透明的,当编译java程序的时候,是将java源文件转成.class文件,java虚拟机去执行这些字节码从而得到执行java程序的目的.那么从.class文件能不能 ...