lightoj 1002
最短路的变形,使用spfa做。
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define INF 0x7fffffff
#define debug cout << "here" << endl
#define CLR(X, Y) memset(X, Y, sizeof X)
#define FOR(X, Y) for(int i = X;i < Y;i ++)
inline int myMin(int x, int y){return x < y ? x : y;}
inline int myMax(int x, int y){return x < y ? y : x;}
const int MAXN = 505;
int mat[MAXN][MAXN], n;
void bfs(int t){
queue<int>Q;
int dist[MAXN], vis[MAXN];
CLR(dist, 1), CLR(vis, 0);
Q.push(t), dist[t] = 0, vis[t] = 1;
while(!Q.empty()){
int u = Q.front();
vis[u] = 0;
Q.pop();
for(int i = 0;i < n;i ++){
if(mat[u][i] > 0){
if(dist[i] > max(mat[u][i], dist[u])){
dist[i] = max(mat[u][i], dist[u]);
if(!vis[i]){
Q.push(i);
vis[i] = 1;
}
}
}
}
}
for(int i = 0;i < n;i ++){
if(dist[i] > 20000) printf("Impossible\n");
else printf("%d\n", dist[i]);
}
}
int main(int argc, char* argv[]){
int t, m, u, v, w;
#ifndef ONLINE_JUDGE
freopen("in.cpp", "r", stdin);
#endif
scanf("%d", &t);
int tmp = t;
while(t--){
printf("Case %d:\n", tmp-t);
memset(mat, 0, sizeof mat);
scanf("%d%d", &n, &m);
for(int i = 0;i < m;i ++){
scanf("%d%d%d", &u, &v, &w);
if(mat[u][v] == 0) mat[u][v] = mat[v][u] = w;
else mat[u][v] = mat[v][u] = min(mat[u][v], w);
}
scanf("%d", &m);
bfs(m);
}
return 0;
}
lightoj 1002的更多相关文章
- Lightoj 1002 - Country Roads(prim算法)
I am going to my home. There are many cities and many bi-directional roads between them. The cities ...
- LightOJ 1341 唯一分解定理
Aladdin and the Flying Carpet Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld &a ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- Light oj 1002 Country Roads (Dijkstra)
题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1002 题目描述: 有n个城市,从0到n-1开始编号,n个城市之间有m条边,中 ...
- Bestcoder#5 1002
Bestcoder#5 1002 Poor MitsuiTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- acm 1002 算法设计
最近突然想往算法方向走走,做了做航电acm的几道题 二话不说,开始 航电acm 1002 题主要是处理长数据的问题,算法原理比较简单,就是用字符数组代替int,因为int太短需要处理的数据较长 下面是 ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5610 如果杠铃总质量是奇数直接impossible 接着就考验耐心和仔细周全的考虑了.在WA了三次后终于发 ...
- 1002. A+B for Polynomials (25)
题目链接:https://www.patest.cn/contests/pat-a-practise/1002 原题如下: This time, you are supposed to find A+ ...
随机推荐
- jQuery 1.4.4 中 function( window, undefined ) 写法原因
读 jQuery 1.4.4 版本代码的时候,发现下面的写法: (function( window, undefined ) { ... // code goes here })(window); w ...
- java oop
/** 多层嵌套内部类, 调用时要层层往下调用 格式: 外部类.内部类1.内部类2 对象名 = new 外部类().new 内部类1().new 内部类2(); 对象名.属性/方法名(); */ cl ...
- android hander 线程用法
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanc ...
- Centos6.5下rsync文件同步安装配置及遇到的问题解决方法
实验节点如下: 源节点:192.168.0.111 备份节点:192.168.0.112 ------------------------------以下部分在两个节点上执行1.防火墙开放873端口( ...
- E8.Net工作流平台开发篇
E8.Net开发篇(一) E8.Net开发框架有哪些源程序模型? E8.Net开发框架为开发企业流程应用系统提供了最佳实践的开发架构.范例及源代码,包括待办事项的组织.流程启动模型.处理模型.母版 ...
- EntityFramework-DBFirst-重新生成后写的验证消失(解决办法)
1.这是EF生成的类: namespace PMS.DataProvider.EntityFramework { using System; using System.Collections.Gene ...
- 开发工具IDEA的使用
一. 先送上IDEA的下载链接 这是我个人的百度云链接,无毒无公害请放心下载~ 链接:http://pan.baidu.com/s/1kUMbatT 密码:i233 巧妇难为无米之炊,如果还没有下载安 ...
- OpenCV学习-b
OpenCV是开源计算机视觉和机器学习库.包含成千上万优化过的算法.项目地址:http://opencv.org/about.html.官方文档:http://docs.opencv.org/modu ...
- 织梦dede_archives文章主表详细介绍
dede_archives文章主表,存放着各频道文章的主要信息,比如创建时间,所属栏目,所属频道,作者等详细的信息. ID int(11) 自动编号typeid int(11) 所属主栏目编号 ...
- Linux 系统挂载数据盘
适用系统:Linux(Redhat , CentOS,Debian,Ubuntu) * Linux的云服务器数据盘未做分区和格式化,可以根据以下步骤进行分区以及格式化操作. 下面的操作将会把数据盘划 ...