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:

  1. long long spfa_slf() {
  2. int n,m;
  3. cin >> n >> m;
  4.  
  5. vector<pair<int,int> > edges111111;
  6. for(int i = ;i < m;i++) {
  7. int x,y,w;
  8. cin >> x >> y >> w;
  9. edgesxx.push_back(make_pair(y,w));
  10. }
  11.  
  12. deque<int> q;
  13. vector<long long> dist(n+, ~0ULL>>);
  14. vector<bool> inQueue(n+, false);
  15. dist11 = ; q.push_back(); inQueue11 = true;
  16.  
  17. int doge = ;
  18. while(!q.empty()) {
  19. int x = q.front(); q.pop_front();
  20. if(doge++ > C) {
  21. puts("doge");
  22. return ;
  23. }
  24. for(vector<pair<int,int> >::iterator it = edgesxx.begin();
  25. it != edgesxx.end();++it) {
  26. int y = it->first;
  27. int w = it->second;
  28. if(distyy > distxx + w) {
  29. distyy = distxx + w;
  30. if(!inQueueyy) {
  31. inQueueyy = true;
  32. if(!q.empty() && distyy > distq.front()q.front())
  33. q.push_back(y);
  34. else
  35. q.push_front(y);
  36. }
  37. }
  38. }
  39. inQueuexx = false;
  40. }
  41. return distnn;
  42. }

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. 1

Sample Output

  1. 4 3
  2. 1 2 1
  3. 2 3 1
  4. 3 4 1

图论  愉悦脑洞题 卡SPFA

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

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

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

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

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

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

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

注意输出顺序也很关键。

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

  1. /*by SilverN*/
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<cmath>
  7. #include<vector>
  8. using namespace std;
  9. int main(){
  10. // freopen("in.txt","w",stdout);
  11. int i,j,C;
  12. while(scanf("%d",&C)!=EOF){
  13. int n=,m=;
  14. // int n=99,m=98/2*3;
  15. printf("%d %d\n",n,m);
  16. /* for(i=3;i<=n;i+=2){
  17. printf("%d %d %d\n",i-2,i,-(1<<(i-1)));
  18. }
  19. for(i=1;i<=n-2;i+=2){
  20. printf("%d %d %d\n",i,i+1,0);
  21. }
  22. for(i=2;i<=n;i+=2){
  23. printf("%d %d %d\n",i,i+1,-(1<<(i-2)));
  24. }*/
  25. for(i=;i<;i++)
  26. printf("%d %d %d\n",i*+,i*+,);
  27. for(i=;i<;i++)
  28. printf("%d %d %d\n",i*+,i*+,-(<<(-i)));
  29. for(i=;i<;i++)
  30. printf("%d %d %d\n",i*+,i*+,-(<<(-i-)));
  31. }
  32. return ;
  33. }

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. 关于实现mybatis order by 排序传递参数实现 问题记录

    一    问题场景:本人项目纯纯的后端系统  并且项目前端采用纯纯的原生js 实现 1)表格  通过查询列表数据放入到域中  前段采用 for循环的方式实现遍历生成列表 2)分页实现本人是公司内部自定 ...

  2. ubuntu 关闭触控板

    第一种: 1 sudo rmmod psmouse    这个是禁用的 2 sudo modprobe psmouse 这个是启用的 这个方法很便捷,但是会将触点和触板都禁用了,一般还是希望保持触点是 ...

  3. 使用Entity Framework出错

          在使用的过程中,写了一个例子,结果就报错说      The context cannot be used while the model is being created.      在 ...

  4. 【面试题】2018年最全Java面试通关秘籍第五套!

    [面试题]2018年最全Java面试通关秘籍第五套! 原创 2018-04-26 徐刘根 Java后端技术 第一套:<2018年最全Java面试通关秘籍第一套!> 第二套:<2018 ...

  5. 形象的理解Strong和Weak

    Strong Weak

  6. 设置socket接收和发送超时的一种方式

    Linux环境设置Socket接收和发送超时: 须如下定义:struct timeval timeout = {3,0};  //设置发送超时setsockopt(socket,SOL_SOCKET, ...

  7. Jmeter——小性能用例

    1.添加默认值,将代理服务器写入 2.添加HTTP请求头,将域名部分用变量形式写入:${__CSVRead(D:/number.txt,0)},这是为了查询不同页面,在D:/number.txt路径下 ...

  8. 教你如何用Docker快速搭建深度学习环境

    本教程搭建集 Tensorflow.Keras.Coffe.PyTorch 等深度学习框架于一身的环境,及jupyter. 本教程使用nvidia-docker启动实例,通过本教程可以从一个全新的Ub ...

  9. 使用JDK的keytool生成Android签名证书

    生成证书:keytool -genkey -alias [yourapp] -keyalg RSA -validity 20000 -keystore [yourapp].keystore 输入key ...

  10. SQLServer数据库慢查询追踪

    不喜欢跟研发扯淡,说点击功能慢,是网络.服务器.运维的锅, 甩手给你打开慢查询,时间超过5s的全部抓取,已经很仁慈了,才抓取大于5s的SQL语句..... SQL SERVER 2014数据库慢查询追 ...