摘要:
http://poj.org/problem?id=1860图论,SPFA好题 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 1000100 5 6 using namespace std; 7 8 int n, m, src; 9 int x[N], y[N], len[N];10 float dist[N];11 bool inQue[N];12 queue<int> que;13 const int inf = 1<<30;14 阅读全文
摘要:
http://poj.org/problem?id=1511图论,最短路,SPFA求所有点到1 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 1000100 5 6 using namespace std; 7 8 int n, m, src; 9 int x[N], y[N], len[N];10 int dist[N];11 bool inQue[N];12 queue<int> que;13 const int inf = 1<< 阅读全文
摘要:
http://poj.org/problem?id=1125最短路,floyd 1 #include <stdio.h> 2 #include <string.h> 3 #define N 123 4 5 int n, g[N][N]; 6 const int inf = 123456; 7 8 int min(int x, int y) 9 {10 return x<y? x: y; 11 }12 13 void floyd()14 {15 int i, j, k;16 for(k=1; k<=n; k++)17 {18 for(i=1; ... 阅读全文
摘要:
http://poj.org/problem?id=3169图论,差分约束系统,SPFA 1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 #define N 1234 5 6 using namespace std; 7 8 int n, m, src; 9 vector<pair<int, int> > g[N];10 int dist[N];11 bool inQue[N];12 queue<int> que;13 int count[N] 阅读全文
摘要:
http://poj.org/problem?id=2387图论,最短路单源最短路,Dijkstra O(N^2) 1 #include <stdio.h> 2 #include <string.h> 3 #define N 1234 4 5 const int inf = 1<<25; 6 int n; 7 int path[N], vis[N]; 8 int cost[N][N], lowcost[N]; 9 10 void dijkstra(int beg)11 {12 int i, j, min1;13 memset(vis, 0, sizeof(v 阅读全文