Fackyyj loves the challenge phase in TwosigmaCrap(TC). One day, he meet a task asking him to find shortest path from vertex 1 to vertex n, in a graph with at most n vertices and m edges. (1 ≤ n ≤ 100,0 ≤ m ≤ n(n-1))

Fackyyj solved this problem at first glance, after that he opened someone's submission, spotted the following code:

 long long spfa_slf() {
int n,m;
cin >> n >> m; vector<pair<int,int> > edges111111;
for(int i = ;i < m;i++) {
int x,y,w;
cin >> x >> y >> w;
edgesxx.push_back(make_pair(y,w));
} deque<int> q;
vector<long long> dist(n+, ~0ULL>>);
vector<bool> inQueue(n+, false);
dist11 = ; q.push_back(); inQueue11 = true; int doge = ;
while(!q.empty()) {
int x = q.front(); q.pop_front();
if(doge++ > C) {
puts("doge");
return ;
}
for(vector<pair<int,int> >::iterator it = edgesxx.begin();
it != edgesxx.end();++it) {
int y = it->first;
int w = it->second;
if(distyy > distxx + w) {
distyy = distxx + w;
if(!inQueueyy) {
inQueueyy = true;
if(!q.empty() && distyy > distq.front()q.front())
q.push_back(y);
else
q.push_front(y);
}
}
}
inQueuexx = false;
}
return distnn;
}

Fackyyj's face lit up with an evil smile. He immediately clicked button "Challenge!", but due to a hard disk failure, all of his test case generators were lost! Fackyyj had no interest on recreating his precise generators, so he asked you to write one. The generator should be able to generate a test case with at most 100 vertices, and it must be able to fail the above code, i.e. let the above code print "doge". It should NOT contain any negative-cost loop.

 For those guys who doesn't know C++, Fackyyj explain the general idea of the above algorithm by the following psuedo-code:

InputInput contains several test cases, please process till EOF. 
 For each test case, there will be a single line containing an integer C. It is the constant C in the above code. (C <= 23333333)OutputFor each test case, on the first line, print two integers, n and m, indicating the number of vertices and the number of edges of your graph. Next m lines, on each line print x y w, means there is a road from x to y, cost w. 
1 ≤ n ≤ 100,0 ≤ m ≤ n(n-1),|w| < 2 31. Note that your output shouldn't contain any negative-cost loop.Sample Input

1

Sample Output

4 3
1 2 1
2 3 1
3 4 1

图论  愉悦脑洞题 卡SPFA

给了一个SPFA的SLF优化程序,让你把它卡掉。

这个SLF的机制大概是每次更新完,如果被更新的点dis比队头dis小,就把它插到队头。

根据这个性质,只要造出数据让它多出许多遍重复的更新即可

http://blog.csdn.net/u012221059/article/details/38336633

↑这里有张图可以很直观地说明问题。可以发现,随着三角数量的增长,复杂度成指数级上升。

莫慌,不加这个鬼畜优化的普通SPFA,复杂度上界还是$O(NM)$的

注释掉的部分可以卡出一定的效果,但是卡不到指数级的样子。

注意输出顺序也很关键。

那么问题来了,我为什么要花时间写这么道没意义的破题?

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
int main(){
// freopen("in.txt","w",stdout);
int i,j,C;
while(scanf("%d",&C)!=EOF){
int n=,m=;
// int n=99,m=98/2*3;
printf("%d %d\n",n,m);
/* for(i=3;i<=n;i+=2){
printf("%d %d %d\n",i-2,i,-(1<<(i-1)));
}
for(i=1;i<=n-2;i+=2){
printf("%d %d %d\n",i,i+1,0);
}
for(i=2;i<=n;i+=2){
printf("%d %d %d\n",i,i+1,-(1<<(i-2)));
}*/
for(i=;i<;i++)
printf("%d %d %d\n",i*+,i*+,);
for(i=;i<;i++)
printf("%d %d %d\n",i*+,i*+,-(<<(-i)));
for(i=;i<;i++)
printf("%d %d %d\n",i*+,i*+,-(<<(-i-)));
}
return ;
}

HDU4889 Scary Path Finding Algorithm的更多相关文章

  1. HDU 4889 Scary Path Finding Algorithm

    其实这个题是抄的题解啦…… 题解给了一个图,按照那个图模拟一遍大概就能理解了. 题意: 有一段程序,给你一个C值(程序中某常量),让你构造一组数据,使程序输出"doge" 那段代码 ...

  2. Proof for Floyd-Warshall's Shortest Path Derivation Algorithm Also Demonstrates the Hierarchical Path Construction Process

    (THIS BLOG WAS ORIGINALLY WRTITTEN IN CHINESE WITH LINK: http://www.cnblogs.com/waytofall/p/3732920. ...

  3. SPFA(Shortest Path Faster Algorithm)

    特别说明 本文转载自三金(frinemore)的博客: 点这 前言 1.关于SPFA,它没死. 2.接下来的所有代码,都是自己手写的(未检查正确性,补充的代码有检查过,是对的),有错误请帮忙指出. S ...

  4. 2014 Multi-University Training Contest 3

    官方解题报告http://blog.sina.com.cn/s/blog_a19ad7a10102uyiq.html Wow! Such Sequence! http://acm.hdu.edu.cn ...

  5. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  6. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  7. Awesome Go (http://awesome-go.com/)

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  8. Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software

    Awesome Go      financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...

  9. [JOI 2017 Final] 足球 (建图,最短路)

    题面 题解 我们可以总结出球的两种状态,要么自己飞,要么在球员脚下被带飞. 自己飞的情况下,他只能单向直线运动,每一步代价为A,被带飞可以乱走,每一步代价为C. 从自己飞到被带飞需要一个距离自己最近的 ...

随机推荐

  1. webpack使用时可能出现的问题

    1.在配置完webpack.config.js准备进行热加载开发时,修改React内容浏览器不会自动局部刷新,而且会console出一些提示: The following modules couldn ...

  2. 用express搭建一个简单的博客系统

    转自:https://blog.csdn.net/qq_29721837/article/details/62055603 Express 简介 Express 是一个简洁而灵活的 node.js W ...

  3. 学习bash——环境配置

    一.环境配置文件的重要性 Bash在启动时直接读取这些配置文件,以规划好bash的操作环境. 即使注销bash,我们的设置仍然保存. 二.login shell 通过完整的登录流程取得的bash,称为 ...

  4. 第十一次ScrumMeeting会议

    第十一次ScrumMeeting 时间:2017/11/18 4:00-4:30 地点:主203 人员:全体人员 照片: 工作情况 名字 今日计划 明天的工作 遇到的困难 蔡帜 讨论策划详情\确定WB ...

  5. JavaSE复习(六)函数式接口

    函数式接口 有且仅有一个抽象方法的接口 @FunctionalInterface注解 一旦使用该注解来定义接口,编译器将会强制检查该接口是否确实有且仅有一个抽象方法,否则将会报错.需要注 意的是,即使 ...

  6. 如何理解流Stream

    百度百科: 计算机中的流其实是一种信息的转换.它是一种有序流,因此相对于某一对象,通常我们把对象接收外界的信息输入(Input)称为输入流,相应地从对象向外输出(Output)信息为输出流,合称为输入 ...

  7. springMVC前后台数据交互

    假设项目需求是在springMVC框架下,后台要传送一个list到前台,那我们就要做以下几个步骤: 1 在web.xml文件中进行springMVC的配置: <?xml version=&quo ...

  8. linux mysql 链接数太小

    Data source rejected establishment of connection,  message from server: "Too many connections&q ...

  9. [UOJ #52]【UR #4】元旦激光炮

    题目大意:交互题,给你三个有序数组,长度分别为$n\_a,n\_b,n\_c$,都不超过$10^5$.三个函数$get\_a(i),get\_b(i),get\_c(i)$,分别返回$a_i,b_i, ...

  10. [洛谷P4390][BOI2007]Mokia 摩基亚

    题目大意: 维护一个W*W的矩阵,每次操作可以增加某格子的权值,或询问某子矩阵的总权值. 题解:CDQ分治,把询问拆成四个小矩形 卡点:无 C++ Code: #include <cstdio& ...