/**** 用dfs并且用了剪枝,为什么还是WA*/
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>using namespace std;const int N = 110;int g[N][N];
bool vis[N];
int n;
int step, dest;
int length[N];void dfs(int s, int dep);int main() {int s;int p, q;int t = 1;#if 0
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endif
#endifwhile (scanf("%d", &n) == 1) {if (n == 0)break;scanf("%d", &s);memset(g, 0x00, sizeof(g));while (scanf("%d%d", &p, &q) == 2) {if (p == 0 && q == 0)break;g[p][q] = 1;}memset(vis, false, sizeof(vis));memset(length, 0, sizeof(length));step = -1;dest = s;vis[s] = true;dfs(s, 0);#if 0int m = 0;int index = 0;for (int i = 1; i <= n; i++) {if (length[i] > m) {m = length[i];index = i;}}
#endifprintf("Case %d: The longest path from %d has length %d, finishing at %d.\n\n",t++, s, step, dest);}return 0;
}void dfs(int s, int dep) {for (int i = 1; i <= n; i++) {if (g[s][i] && !vis[i]) {vis[i] = true;if (dep + 1 > length[i]) {length[i] = dep + 1;dfs(i, dep + 1);}vis[i] = false;}}if (dep > step) {step = dep;dest = s;}
}

UVa10000 - Longest Paths(为什么是WA)相关推荐

  1. Cow Contest POJ - 3660 And Longest Paths UVA - 10000(弗洛伊德的应用)

    Problem Description N ( 1 ≤ N ≤ 100 ) N (1 ≤ N ≤ 100) N(1≤N≤100) cows, conveniently numbered 1.. N 1 ...

  2. UVa10000_Longest Paths(最短路SPFA)

    解题报告 求最长路. 用SPFA求最长路,初始化图为零,dis数组也为零 #include <iostream> #include <cstdio> #include < ...

  3. 2016 10 26考试 NOIP模拟赛 杂题

    Time 7:50 AM -> 11:15 AM 感觉今天考完后,我的内心是崩溃的 试题 考试包 T1: 首先看起来是个贪心,然而,然而,看到那个100%数据为n <= 2000整个人就虚 ...

  4. Paper:2017年的Google机器翻译团队《Transformer:Attention Is All You Need》翻译并解读

    Paper:2017年的Google机器翻译团队<Transformer:Attention Is All You Need>翻译并解读 目录 论文评价 1.Motivation: 2.创 ...

  5. ICPC-图论知识与算法要览

    1.图定义(Definitions in graph theory) 1)图(Graph) 2)有向图(Directed graph) 3)图数据表示 邻接矩阵(Adjacency Matrix),邻 ...

  6. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  7. π-Algorithmist分类题目(3)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(3) Probability ...

  8. π-Algorithmist分类题目(2)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(2) Set Theory U ...

  9. 数据结构与算法 学习笔记(中)

    油管上的CS61B的视频 学习代码 随看随记 Dijkstra's algorithm再理解 Asymptotics 本意是渐近的意思:这里代指当参数为无穷大时,所需要进行运算的次数,和我们常说的复杂 ...

最新文章

  1. SQL Server-流程控制 5,Goto 语句
  2. 面试官:kill -9 进程杀不掉,怎么办?
  3. golang []byte 和 string相互转换
  4. ASP.NET Core Web API + Identity Server 4 + Angular 6 实战小项目视频
  5. SpringBoot运行原理初探
  6. fortran语法笔记
  7. spark学习-SparkSQL-java版JavaRDD与JavaPairRDD的互相转换
  8. WORD中插入的公式与文字对不齐——公式比文字高——文字比公式低
  9. html5开发桌面程序调用dll,使用Visual Studio开发Html5应用
  10. 阿里图标库iconfont下载和在旧有的iconfont中添加新的图标
  11. 如何对matlab .m代码文件进行加密
  12. java常用的排序方法
  13. PS笔记:调色部分实践基础
  14. linux vi 查找内容
  15. 如何利用python计算即期利率_利用 Python 进行量化投资分析 - 利率及风险资产的超额收益-Go语言中文社区...
  16. 淼淼刷力扣(PTA特别版2)
  17. 如何制作家庭网络服务器,如何用一个废旧的笔记本打造一个家庭网络服务器?...
  18. Linux线程操作以及相关知识
  19. 【ISP】HSV(2)
  20. AV3680A天馈线测试仪使用方式

热门文章

  1. 用 Shell 脚本访问 MySQL 数据库
  2. 商业领袖摘下帽子才能炼成极致
  3. pythonweb开发-如何用Python做Web开发?——Django环境配置
  4. 用python绘制漂亮的图形-python如何画出漂亮的地图?
  5. python处理excel表格大小-如何用python处理excel表格
  6. 基于python的数据挖掘网课-利用 Python 练习数据挖掘
  7. python 调用linux命令-Python调用shell命令常用方法
  8. python基础代码库-CNN详解-基于python基础库实现的简单CNN
  9. 2018python培训-参加python培训要多少钱?
  10. python csv读取-Python对于CSV文件的读取与写入