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 ;
}

最新文章

  1. 十一. 一步步破解JEB 2.0demo版一
  2. oracleclient连oracle库 报System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本
  3. 03Mybatis_mybatis框架原理——执行流程
  4. (转)SQL对Xml字段的操作
  5. Unix 基础IO
  6. C#获取设备的IP和Mac类
  7. Nginx + unicorn 运行多个Rails应用程序
  8. C# 遍历本地网络
  9. CentOS6.6 搭建Zabbix_3.0
  10. Java内存使用量测试
  11. 笔记:MyBatis Mapper XML文件详解 - 映射和参数
  12. SQLServer之修改数据库架构
  13. CentOS7 使用firewalld打开关闭防火墙与端口
  14. jquery第一篇
  15. WebSocket原理与实践(一)---基本原理
  16. linux 同步IO: sync、fsync与fdatasync、sys_sync【转】
  17. python基础(四)——正则表达式
  18. vue-cil 中的配置分析
  19. watch案例解析(element-ui el-select 无法选中问题剖析)
  20. Linux 下shell 编程学习脚手架

热门文章

  1. 关于 spring-aop理解
  2. ORB-SLAM 代码笔记(三)tracking原理
  3. Eclipse 导入项目与 svn 插件关联全过程记录
  4. 教你用Bootstrap开发漂亮的前端界面
  5. XPATH之normalize-space(.)和normalize-space(text())区别
  6. HDFS分布式集群
  7. python第一天(安装运行python)
  8. js日期插件bootstrap-datetimepicker的使用
  9. DP入门(3)——多阶段决策问题
  10. CentOS 7 samba 配置