soj 4526 不重叠最短路条数
来源:互联网 发布:营改增减税数据 编辑:程序博客网 时间:2024/06/16 07:52
分析:记录路径,每一次最短路都删去边,最后最短路变长了就停止。
/**********************jibancanyang************************** *Author* :jibancanyang *Created Time* : 一 5/30 17:18:48 2016**Problem**:**Analyse**:**Get**:**Code**:***********************1599664856@qq.com**********************/#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <stack>using namespace std;typedef pair<int, int> pii;typedef long long ll;typedef unsigned long long ull;vector<int> vi;#define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl;#define pri(a) printf("%d\n",(a));#define xx first#define yy second#define sa(n) scanf("%d", &(n))#define sal(n) scanf("%lld", &(n))#define sai(n) scanf("%I64d", &(n))#define vep(c) for(decltype((c).begin() ) it = (c).begin(); it != (c).end(); it++) const int mod = int(1e9) + 7, INF = 0x3f3f3f3f;const int maxn = 1e3 + 13;struct node { int to, cost; node (int A, int B): to(A), cost(B) {}};int vis[maxn][maxn];int logs[maxn][maxn];vector<node> G[maxn];int d[maxn], pre[maxn],s, e, n, m;int dijkstra(void) { fill(d + 1, d + n + 1, INF); priority_queue<pii, vector<pii>, greater<pii> > que; que.push(pii(0, s)); d[s] = 0; pre[s] = -1; while (!que.empty()) { pii cur = que.top(); que.pop(); if (cur.yy == e) return cur.xx; if (cur.xx > d[cur.yy]) continue; for (int i = 0; i < (int)G[cur.yy].size(); i++) { node nxt = G[cur.yy][i]; if (vis[cur.yy][nxt.to] <= 0) continue; if (d[nxt.to] > cur.xx + nxt.cost) { d[nxt.to] = cur.xx + nxt.cost; que.push(pii(d[nxt.to], nxt.to)); pre[nxt.to] = cur.yy; } } } return -1;}int main(void){#ifdef LOCAL freopen("/Users/zhaoyang/in.txt", "r", stdin); //freopen("/Users/zhaoyang/out.txt", "w", stdout);#endif int T; sa(T); while (T--) { memset(vis, 0, sizeof(vis)); sa(n), sa(m); for (int i = 1; i <= n; i++) fill(logs[i] + 1, logs[i] + n + 1, INF); for (int i = 0; i < m; i++) { int x, y, z; sa(x), sa(y), sa(z); if (z < logs[x][y]) {vis[x][y] = 1; logs[x][y] = z;} else if (z == logs[x][y]) vis[x][y]++; else continue; G[x].push_back(node(y, z)); } sa(s), sa(e); int mins = dijkstra(), ans = 0; if (mins == -1) puts("0"); else { while (true) { ans++; int x = e; while (pre[x] != -1) { // pr(pre[x]), pl(x); vis[pre[x]][x]--; x = pre[x]; } x = dijkstra(); if (x != mins) break; } pri(ans); } } return 0;}
0 0
- soj 4526 不重叠最短路条数
- 最短路条数
- zoj 2760(边不相交最短路的条数)
- CDOJ_1147 (最短路条数)
- 最短路条数模板
- 最短路条数计数
- POJ_3463_Sightseeing(最短路/次短路条数)
- 最短路和次短路条数
- poj3463Sightseeing(最短路条数+次短路条数)
- 求最短路条数之类的~~~
- 1796 社交网络[最短路条数]
- zoj How Many Shortest Path 网络流 不相交最短路条数
- ZOJ 2760 How Many Shortest Path 边不相交最短路条数
- HDU-1688 Sightseeing 最短路与“次短路”条数
- hdu 1688 Sightseeing【最短路,次短路条数】
- hdu 1688 Sightseeing(最短路+次短路条数)
- POJ-3463: Sightseeing 【最短路次短路及条数】
- hdu 6181 Two Paths -最短路条数+次短路
- iOS 市内检索
- 解决WPS转PDF出现OLE_LINK问题
- material design的设计思想 转载
- 调用百度apiStore的天气 自动获取地址 及本地天气
- Git入门就是这么简单
- soj 4526 不重叠最短路条数
- valign属性
- Java 关键字之this
- Golang defer 使用时的坑
- oracle 性能优化建议小结
- sort-list(Leetcode)
- make -C $(kdir) M=$(pwd) modules
- css 重置样式
- 表格的示例