专题四 · 1010
来源:互联网 发布:行情软件破解 编辑:程序博客网 时间:2024/05/29 01:51
代码及解释
#include <stdio.h>#include <iostream>#include <queue>// 最短路之后深搜// 用的队列优化////typedef struct n1 { int distens, flog; } node;node N[1005];int map[1005][1005], k;int direct[1005];void set(int n) { int i, j, m, n1, n2, d; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { map[i][j] = -1; } N[i].distens = 10000000; N[i].flog = 0; direct[i] = 0; } scanf("%d", &m); while (m--) { scanf("%d%d%d", &n1, &n2, &d); if (map[n1][n2] != 0 || map[n1][n2] > d) map[n1][n2] = map[n2][n1] = d; }}void spfa(int n) { std::queue<int> Q; int now; int i; N[2].distens = 0; N[2].flog = 1; Q.push(2); while (!Q.empty()) { now = Q.front(); Q.pop(); N[now].flog = 0; for (i = 1; i <= n; i++) if (map[now][i] != -1) { if (N[i].distens > N[now].distens + map[now][i]) { N[i].distens = N[now].distens + map[now][i]; if (N[i].flog == 0) { N[i].flog = 1; Q.push(i); } } } }}int DFS(int now, int n) { int i; if (direct[now] > 0) return direct[now]; if (now == 2) { return 1; } for (i = 1; i <= n; i++) if (map[now][i] != -1 && N[now].distens > N[i].distens) direct[now] += DFS(i, n); return direct[now];}int main() { int n; while (scanf("%d", &n) > 0 && n) { set(n); spfa(n); k = DFS(1, n); printf("%d\n", k); }}
0 0
- 专题四 · 1010
- 专题四1010
- 1010-J专题四
- 专题四 · 1001
- 专题四 · 1002
- 专题四 · 1003
- 专题四 · 1004
- 专题四 · 1006
- 专题四 · 1005
- 专题四 · 1008
- 专题四 · 1009
- 专题四 · 1011
- 3G专题四
- LDAP专题(四)
- 专题四1003
- 专题四1003
- 专题四 Problem A
- 专题四 Problem B
- csdn一个神奇的网站
- LeetCode刷题系列(十五)Sums && Sort Colors
- iOS开发经验相关知识
- BZOJ1264——[AHOI2006]基因匹配Match
- 多任务
- 专题四 · 1010
- 弹出对话框
- quartz任务调度执行时每次都执行两次
- Android.mk详解
- iOS 给文字上面加贯穿横线
- 在Ubuntu 14.04(64bit)上搭建Android编译环境(通用版)
- 链表:删除链表中重复的结点(java实现)
- 玩转树莓派之三----使用VNC viewer远程桌面访问树莓派
- 读书笔记-java网络编程-7URLConnection-获取URL首部