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. Sql Server 2008 R2数据库中插入中文变成了问号

            通过Insert语句插入数据库中,结果中文都变成了乱码.原因是在数据库中有一个属性需要设置,可以通过Sql server manager studio来进行设置,也要可以通过代码来设置 ...

  2. 2,理解JVM

      一.内存管理:   1,内存结构: 栈和堆区别,栈是连续内存区,一般是2M单位,堆是不连续的链表.受限于虚拟内存,new时分配 PC寄存器.java栈.堆.方法区.本地方法区.运行常量池 java ...

  3. jmeter-maven-plugin

    Maven编译JMeter, 使用的是jmeter-maven-plugin插件: <?xml version="1.0" encoding="UTF-8" ...

  4. laxcus的新功能:支持表跨数据库操作

    关系数据库的层次结构,是账号.数据库.表,一个账号下可以有多个数据库,每个数据库有多个表,但是不同数据库下的表是不能够互相操作的.例如:"select a.*, b.* from Title ...

  5. Python——数据类型之set

    本篇主要内容 • set集合的特点 • set集合的建立 • set集合的17个内置函数 • set集合的数学运算符号 1.set集合类型的特点. 1.无序 2.不同元素 3.元素必须不可变.(数字, ...

  6. 使用idea工具开发webservice

    在idea开发工具中使用axis2插件创建集成webservice的web项目: 一.创建java项目                  二.添加webservices支持 在红线框2处选择要使用的w ...

  7. MongoDB复制二:复制集的管理

    1.修改oplog的大小  需要在每个机器上都配置.先在secondary上操作,最后在primary上操作. 1)以单机的方式重启复制集的实例 db.shutdownServer() 在新的端口中启 ...

  8. c语言实现带LRU机制的哈希表

    #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  9. 左右躲避障碍-神手ts版本

    TypeScript-左右躲避障碍-神手 学习typescript,第一步应该是学习官方文档,理解最基础的语法.第二步开始用typescript实现一些js+css 或者canvas类型的游行.现在开 ...

  10. 用Web Service实现客户端图片上传到网站

    由于项目需要,通过本地客户端,把图片上传到网站.通过webservice. 这是客户端代码: private void btnimg_Click(object sender, EventArgs e) ...