BNUOJ-26480 Horror List 最短路
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26480
题意:简单来说,就是给一个图,然后从每个honor list中的点求最短路。。
边权值为1,Bfs就可以了,注意这里是无向图。。
//STATUS:C++_AC_84MS_1788KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
//#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=1e9+,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Edge{
int u,v;
}e[N**];
int first[N],next[N**],vis[N],hig[N];
int n,m,L,mt; void adde(int a,int b)
{
e[mt].u=a,e[mt].v=b;
next[mt]=first[a],first[a]=mt++;
e[mt].u=b,e[mt].v=a;
next[mt]=first[b],first[b]=mt++;
} queue<int> q;
void bfs()
{
int i,j,u,v;
while(!q.empty())
{
u=q.front();q.pop();
for(i=first[u];i!=-;i=next[i]){
v=e[i].v;
if(vis[v])continue;
vis[v]=;
hig[v]=hig[u]+;
q.push(v);
}
}
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,k,a,b,c;
while(~scanf("%d%d%d",&n,&m,&L))
{
mem(first,-);mt=;
mem(hig,INF);
mem(vis,);
for(i=;i<m;i++){
scanf("%d",&a);
hig[a]=;
q.push(a);
vis[a]=;
}
for(i=;i<L;i++){
scanf("%d%d",&a,&b);
adde(b,a);
} bfs();
int ans=,answ=;
for(i=;i<n;i++){
if(hig[i]>ans){
ans=hig[i];
answ=i;
}
} printf("%d\n",answ);
}
return ;
}
BNUOJ-26480 Horror List 最短路的更多相关文章
- BNU 26480 Horror List【最短路】
链接: http://www.bnuoj.com/bnuoj/problem_show.php?pid=26480 http://www.bnuoj.com/bnuoj/contest_show.ph ...
- BNUOJ 52303 Floyd-Warshall Lca+bfs最短路
题目链接: https://www.bnuoj.com/v3/problem_show.php?pid=52303 Floyd-Warshall Time Limit: 60000msMemory L ...
- bzoj1001--最大流转最短路
http://www.lydsy.com/JudgeOnline/problem.php?id=1001 思路:这应该算是经典的最大流求最小割吧.不过题目中n,m<=1000,用最大流会TLE, ...
- 【USACO 3.2】Sweet Butter(最短路)
题意 一个联通图里给定若干个点,求他们到某点距离之和的最小值. 题解 枚举到的某点,然后优先队列优化的dijkstra求最短路,把给定的点到其的最短路加起来,更新最小值.复杂度是\(O(NElogE) ...
- Sicily 1031: Campus (最短路)
这是一道典型的最短路问题,直接用Dijkstra算法便可求解,主要是需要考虑输入的点是不是在已给出的地图中,具体看代码 #include<bits/stdc++.h> #define MA ...
- 最短路(Floyd)
关于最短的先记下了 Floyd算法: 1.比较精简准确的关于Floyd思想的表达:从任意节点A到任意节点B的最短路径不外乎2种可能,1是直接从A到B,2是从A经过若干个节点X到B.所以,我们假设maz ...
- bzoj1266最短路+最小割
本来写了spfa wa了 看到网上有人写Floyd过了 表示不开心 ̄へ ̄ 改成Floyd试试... 还是wa ヾ(。`Д´。)原来是建图错了(样例怎么过的) 结果T了 于是把Floyd改回spfa 还 ...
- HDU2433 BFS最短路
Travel Time Limit: 10000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- 最短路(代码来源于kuangbin和百度)
最短路 最短路有多种算法,常见的有一下几种:Dijstra.Floyd.Bellman-Ford,其中Dijstra和Bellman-Ford还有优化:Dijstra可以用优先队列(或者堆)优化,Be ...
随机推荐
- python参考手册--第3章类型和对象
1.对象的身份.类型.值 (1)身份:对象在内存中位置的指针,地址值, >>> a = [1,2,3,4,5] >>> id(a)48497328 >> ...
- 16进制字符串转数字(C/C++,VB/VB.net,C#)
这个问题看是很简单,但是在不同语言中实现的方式却千差万别,如果不知道方法,还真是麻烦,我就是在C#中遇到该问题,让我费了很大的周折,才在msdn查到. 一.16进制字符串转数字 1.C/C+ ...
- Windows平台上C++开发内存泄漏检查方法
充分的利用调试工具可以非常方便地避免内存泄漏问题. 这里介绍两种方法,互为补充,第一种是VC编译器提供的方法,第二种是专用的内存泄漏检查工具Memmory Validator.这两种方法的基本原理是一 ...
- 【leetcode】3Sum Closest(middle)
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- [itint5]两有序数组的交和并
这一题也简单,唯一有意思的地方是提炼了一个函数用来做数组索引去重前进. int forward(vector<int> &arr, int i) { while (i+1 < ...
- mac中用命令行运行mysql
1,安装mysql 在mysql的官方网站下载 mysql 5.5.23 http://www.mysql.com/downloads/mysql/,根据我的机器的配置情况选择了64bit版本. 2, ...
- WinAPI——Windows 消息
消息 值 注释 WM_NULL $0000 WM_CREATE $0001 WM_DESTROY $0002 WM_MOVE $0003 WM_SIZE $0005 WM_AC ...
- C#中的线程(三) 使用多线程
第三部分:使用多线程 1. 单元模式和Windows Forms 单元模式线程是一个自动线程安全机制, 非常贴近于COM——Microsoft的遗留下的组件对象模型.尽管.NET最大地放弃摆脱了遗留 ...
- poj1151Atlantis(离散化+扫描线)
http://poj.org/problem?id=1151 http://www.cnblogs.com/kane0526/archive/2013/02/26/2934214.html这篇博客写的 ...
- 根据block取出页号buf_block_get_page_no
/*********************************************************************//** Gets the page number of a ...