[BZOJ3417]Poi2013 Tales of seafaring Description 一个n点m边无向图,边权均为1,有k个询问 每次询问给出(s,t,d),要求回答是否存在一条从s到t的路径,长度为d 路径不必是简单路(可以自交) 2<=N<=5000,1<=M<=5000,1<=K<=1000000,1<=d<=1000000000 Sample Input 8 7 4 1 2 2 3 3 4 5 6 6 7 7 8 8 5 2 3 1 1…
题目描述 Young Bytensson loves to hang out in the port tavern, where he often listens to the sea dogs telling their tales of seafaring. Initially, he believed them all, however incredible they sounded. Over time though, he became suspicious. He has decid…
关于几个的区别和联系:http://www.cnblogs.com/zswbky/p/5432353.html d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到这个城市的距离设为0),草儿想去的地方有D个: 求D个城市中距离草儿家最近的距离. s.进行1次单源最短路,找出距离最小的即可. c.Dijkstra单源最短路 /* Dijkstra单源最短路 权值必须是非负 单源最短路径,Dijkstra算法,邻接矩阵形式,复杂度为O(n^2) 求出源beg到所…
L - Subway(最短路spfa) You have just moved from a quiet Waterloo neighbourhood to a big, noisy city. Instead of getting to ride your bike to school every day, you now get to walk and take the subway. Because you don't want to be late for class, you want…
[POI2013]MOR-Tales of seafaring 题目描述 一个n点m边无向图,边权均为1,有k个询问 每次询问给出(s,t,d),要求回答是否存在一条从s到t的路径,长度为d 路径不必是简单路(可以自交) 输入样例#1: 8 7 4 1 2 2 3 3 4 5 6 6 7 7 8 8 5 2 3 1 1 4 1 5 5 8 1 8 10 输出样例#1: TAK NIE TAK NIE 题解 没有时间了,先放代码,明天补坑... #include<iostream> #inclu…
若x到y走k步可行,那么走k+2步也可行 以每个点为起点,BFS处理出到每个点走了奇数步.偶数步的最短路 对于一次询问,如果d不小于相应奇偶性的最短路,则可行 特判:对于孤立点,无论怎么走都不可行 #include<cstdio> const int N=10010,Q=1000010; int n,m,k,i,j,x,y,z,g[N],nxt[N],v[N],ed,G[N],NXT[Q],V[Q],W[Q],ED,dis[N][2],pos[N][2],q[N][2],h,t; inline…
传送门 这个题比较水,很容易看出 1.最短路小于d,直接看奇偶性就好了 2,最短路大于d,puts("NIE\n"); 主要就是判奇偶性的问题,将每个点拆成奇点和偶点跑bfs就行了 在线需要开short,不然空间会炸,离线就没有这个忧虑 代码: #include<cstdio> #include<iostream> #include<algorithm> #include<queue> using namespace std; void…
求单源最短路到其余各点,然后返回源点的总最短路长,以构造邻接表的方法不同分为两种解法. POJ1511(ZOJ2008)-Invitation Cards 改变构造邻接表的方法后,分为两种解法 解法一: //POJ1511-ZOJ2008 //Time:7766Ms Memory:99112K //求从1处到各点后再返回1处的最短总路长 //需要构造邻接表和逆邻接表 //构造方法1:vector构造邻接表 //SPFA+邻接表 #include<iostream> #include<cs…
题意很好懂,但是不好下手.这里可以把每个点编个号(1-25),看做一个点,然后能够到达即为其两个点的编号之间有边,形成一幅图,然后求最短路的问题.并且pre数组记录前驱节点,print_path()方法可用算法导论上的. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <ve…
http://poj.org/problem?id=3255 同匈牙利游戏. 但是我发现了一个致命bug. 就是在匈牙利那篇,应该dis2单独if,而不是else if,因为dis2和dis1相对独立.有可能在前边两个if改了后还有更优的次短路. 所以,,wikioi那题太水,让我水过了.. #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <…