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+ ...
随机推荐
- 实现一个div在浏览器水平居中
第一种方法: div { margin: 0 auto; width: 960px; } 第二种方法(兼容IE): body { text-align: center; } div { margin: ...
- NOSQL之【Redis学习:配置说明】
# yes:后台运行:no:不是后台运行(老版本默认) daemonize yes # redis的进程文件 pidfile /var/run/redis.pid # 端口 port # bind_a ...
- JavaScript事件总结
JavaScript 事件总结 本文总结自<JavaScript高级程序设计>以及自己平时的经验,针对较新浏览器以及 DOM3 级事件标准(2016年8月),对少部分内容作了更正,增加 ...
- jquery div拖动效果示例代码
div拖动效果想必大家都有见到过吧,实现的方法也是有很多的,下面为大家将介绍使用jquery是如何实现的,感兴趣的朋友不要错过 复制代码代码如下: <%@ page language=" ...
- j2ee中如何拦截jsp页面?
加filter: public class RightFilter implements Filter { public void init(FilterConfig filterConfig) th ...
- C#中的==、Equal、ReferenceEqual(转载)
1. ReferenceEquals, == , Equals Equals , == , ReferenceEquals都可以用于判断两个对象的个体是不是相等. a) ReferenceEquals ...
- hdu 1568 Fibonacci 数学公式
Fibonacci Problem Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到的Fibonacci数列(f[0]=0,f[1]=1;f[i] = ...
- FolderBrowserDialog组件选择文件夹
1.选择路径 this.folderBrowserDialog1.ShowDialog(); if (this.folderBrowserDialog1.ShowDialog() == DialogR ...
- Oracle存储过程创建及调用(转)
在大型数据库系统中,有两个很重要作用的功能,那就是存储过程和触发器.在数据库系统中无论是存储过程还是触发器,都是通过SQL 语句和控制流程语句的集合来完成的.相对来说,数据库系统中的触发器也是一种存储 ...
- Linux中tty、pty、pts的概念区别
转自Linux中tty.pty.pts的概念区别 基本概念: 1> tty(终端设备的统称): tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过 ...