九度oj 1545奇怪的连通图
来源:互联网 发布:企搜通软件 编辑:程序博客网 时间:2024/05/16 02:14
很笨地用DFS递归枚举。。
然后果断超时。。
一个数据都没过。。
然后第二天早上起来果断用BFS写了一下。。
wa~~
有点小激动,因为没有超时。
然后将队列改为优先队列果断A了
yes!!
#include<cstdio>#include<cstring>#include<vector>#include<queue>using namespace std;struct node{ int ne; int va;};struct node1{int next;int m;bool operator < (const node1& a) const{return m>a.m;}};vector<node> map[10002];int visit[10002];int n,t,in;int mmin(int aa,int bb){ return aa<bb?aa:bb;}int max(int aa,int bb){ return aa>bb?aa:bb;}int BFS(){int xiao = 1000008;priority_queue<node1> qu;struct node1 needru,needpush,var;needru.next = 1;needru.m = 0;qu.push(needru);visit[1] = 1;while(!qu.empty()){needpush = qu.top();qu.pop();if(needpush.next==n)xiao = mmin(xiao,needpush.m);int len = map[needpush.next].size();visit[needpush.next] = 1;for(int i=0;i<len;i++){if(!visit[map[needpush.next][i].ne]){var.next = map[needpush.next][i].ne;var.m = max(map[needpush.next][i].va,needpush.m);qu.push(var);}}}return xiao;}int main(){ int i,j,a,b; struct node qq; while(scanf("%d%d",&n,&t)!=EOF) { in = 1000008; memset(visit,0,sizeof(visit)); for(i=0;i<t;i++) { scanf("%d%d%d",&a,&b,&j); qq.ne = b; qq.va = j; map[a].push_back(qq); qq.ne = a; map[b].push_back(qq); } visit[1] = 1;in = BFS(); if(in!=1000008) printf("%d\n",in); else printf("-1\n"); for(i=0;i<=n;i++) map[i].clear(); } return 0;}
- 九度oj 1545奇怪的连通图
- 九度OJ 1545 奇怪的连通图
- <九度 OJ>题目1545:奇怪的连通图
- 【九度】题目1545:奇怪的连通图
- 九度oj 题目1109:连通图
- 九度oj-1109-连通图
- 九度OJ - 1109 - 连通图
- 九度OJ 1109 连通图
- 九度OJ-1109:连通图
- 题目1109:连通图 九度OJ
- 九度OJ题目1109:连通图
- 奇怪的连通图
- 题目1545:奇怪的连通图
- 题目1545:奇怪的连通图
- 九度OJ 1109:连通图 (最小生成树)
- 【九度OJ】题目1109:连通图 解题报告
- 九度OJ——1109连通图
- 奇怪的连通图_1545
- JAVA 上加密算法的实现用例
- 浅谈原始套接字 SOCK_RAW 的内幕及其应用(port scan, packet sniffer, syn flood, icmp flood)
- 判断老版本iOS SDK
- 组函数 注意的地方
- 示波器触发技术
- 九度oj 1545奇怪的连通图
- 标准模板STL简介
- 示波器的触发功能
- "could not create the java virtual machine"启动eclipse报错
- Windows服务编写综述
- 骨骼动画的研究
- android中类似 QQ震动窗口的实现,带声音和振动效果
- VC++界面编程之--使用分层窗口实现界面皮肤
- 道德经之信而贵言