【Hautoj 1278 Transmit information】+ dfs
来源:互联网 发布:工程图纸设计软件 编辑:程序博客网 时间:2024/06/07 00:41
1278: Transmit information
时间限制: 3 秒 内存限制: 128 MB
提交: 24 解决: 13
提交 状态
题目描述
The Chinese people threw themselves into an all-out war of resistance against Japanese aggression in 1937. The first line of resistance against aggression was formed by spies and underground workers.
They lurked in every place of the city.
There’s a piece of information that needs to be passed on to them. Now there is a traffic map, each road connects two different intersections Xi and Yi, each of which is the termination for at least two road. The length of each road is known LENi, no two intersections are directly connected by two different roads.
N spies lurk at every intersection , some intersections mignt have more than one spy. For security, they must position themselves properly , each spy cannot accept information from local intersection , can only be transferred from elsewhere and end up at the finishing pace.
At first, the information is in the hands of a spy at S intersection. After N spies transmission, and finally arrived at E intersection .
Write a program to find the shortest path that connects the starting intersection(S) and the ending intersection(E) ang transmission exactly N spies.
输入
The first line of the input contains one integers T, which is the nember of test cases (1<=T<=5). Each test case specifies:
- Line 1: Four space-separated integers: N M S E
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: LENi Xi Yi
( 2<=N<=300,000 2<=M<=100, 1<= LENi, Xi, Yi ,S, E <=1000 i=1,…,m)
输出
For each test case generate a single line containing a single integer that is the shortest path from intersection S to intersection E that transmits exactly N spies.
样例输入
1
2 6 6 4
11 4 6
4 4 8
8 4 9
6 6 8
2 6 9
3 8 9
样例输出
10
提示
暴力 dfs
AC代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{ int to,vl,next;}st[210];int head[1010],vis[1010],n,num,ans;void add(int a,int b,int vl){ st[num].vl = vl,st[num].to = b,st[num].next = head[a],head[a] = num++;}void dfs(int a,int cut,int en,int sum){ for(int i = head[a]; i ;i = st[i].next){ int o = st[i].to; if(!vis[o]){ vis[o] = 1; if(cut + 1 == n && en == o) ans = min(ans,sum + st[i].vl); else if(cut + 1 < n) dfs(o,cut + 1,en,sum + st[i].vl); vis[o] = 0; } }}int main(){ int T,m,s,e; scanf("%d",&T); while(T--){ num = 0; scanf("%d %d %d %d",&n,&m,&s,&e); while(m--){ int vl,a,b; scanf("%d %d %d",&vl,&a,&b); add(a,b,vl),add(b,a,vl); } ans = 0x3f3f3f; vis[s] = 1,dfs(s,0,e,0); printf("%d\n",ans); memset(vis,0,sizeof(vis)); memset(head,0,sizeof(head)); } return 0;}
- 【Hautoj 1278 Transmit information】+ dfs
- haut 1278: Transmit information(倍增floyd)@
- Transmit
- 河南第十届ACM省赛-I-Transmit information
- 【hautoj 1281】邪能炸弹 【dfs 暴力】or 【dp】
- 河南省第十届ACM省赛题目:问题 I: Transmit information
- (关系幂运算->n长度的最短路)河南省第十届ACM省赛题目:问题 I: Transmit information
- HAUTOJ 1265
- hautoj 1260
- HAUTOJ company
- socket file transmit
- Transmit File使用
- link layer transmit
- Codeforces 466E Information Graph(dfs+并查集)
- information
- HAUTOJ G题
- HAUTOJ-1267 ch追妹
- HAUTOJ 1268: 小天使改名
- Linux配置JForum的一些常用命令及操作
- HBase配置snappy
- MySql 命令,语法(持续更新中…..欢迎大家在下面留言)
- python装饰器的4中类型:函数装饰函数、函数装饰类、类装饰函数、类装饰类
- 什么是IDE
- 【Hautoj 1278 Transmit information】+ dfs
- iOS Protocol Buffers的搭建详细过程
- SpringMVC的<mvc:default-servlet-handler/>
- iptable filter表
- Storm简单介绍
- Tomcat使用(一) web应用打包war文件放入到linux的tomcat中
- 用简单的lnmp实现的论坛搭建
- 宏定义
- UVA1594解题报告