接下来是我们提供的所有程序的伪代码;变量 counter 近似描述出了程序的运行时间。评测时将会使用这些伪代码的 C++ 版本来进行评测。
FloydWarshall
// pre-condition: the graph is stored in an adjacency matrix M
counter =0for k =0 to V-1for i =0 to V-1for j =0 to V-1
increase counter by 1;
M[i][j]=min(M[i][j], M[i][k]+ M[k][j]);for each query p(s,t)
output M[s][t];
OptimizedBellmanFord
// pre-condition: the graph is stored in an adjacency list L
counter =0for each query p(s,t);
dist[s]=0;// s is the source vertex
loop V-1 times
change =false;for each edge(u,v) in L
increase counter by 1;if dist[u]+weight(u,v)< dist[v]
dist[v]= dist[u]+weight(u,v);
change =true;if change is false// this is the ’optimized’ Bellman Ford
break from the outermost loop;
output dist[t];
ModifiedDijkstra
// pre-condition: the graph is stored in an adjacency list L
counter =0;for each query p(s,t)
dist[s]=0;
pq.push(pair(0, s));// pq is a priority queue
while pq is not empty
increase counter by 1;(d, u)= the top element of pq;
remove the top element from pq;if(d == dist[u])for each edge(u,v) in L
if(dist[u]+weight(u,v))< dist[v]
dist[v]= dist[u]+weight(u,v);
insert pair (dist[v],v)into the pq;
output dist[t];
Gamble1
Sets X = V;
labels vertex i in [0..V-1] with i;
Sets counter =0;// will never get TLE
Gamble2
Sets X = V;
labels vertex i in [0..V-1] with i;
Sets counter =1000001;// force this to get TLE
RecursiveBacktracking
This algorithm tries X from 2 to V one by one and stops at the first valid X.For each X, the backtracking routine label vertex 0 with 0, then for each vertex u that has been assigned a label, the backtracking routine tries to assign
the smallest possible label up to label X-1 to its neighbor v,and backtracks if necessary.// Please check RecursiveBacktracking.cpp/pas to see
// the exact lines where the iteration counter is increased by 1