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 ...
随机推荐
- 一分钟明白 VS manifest 原理
什么是vs 程序的manifest文件 manifest 是VS程序用来标明所依赖的side-by-side组建,如ATL, CRT等的清单. 为什么要有manifest文件 一台pc上,用一组建往往 ...
- hdu 1849 Rabbit and Grass 博弈论
水题,转化Nim 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include&l ...
- CodeChef November Challenge 2014
重点回忆下我觉得比较有意义的题目吧.水题就只贴代码了. Distinct Characters Subsequence 水. 代码: #include <cstdio> #include ...
- UIWebView和UIWebViewDelegate的基本用法
UIWebView和UIWebViewDelegate的基本用法 一.UIWebView主要有三种方法实现页面的装载,分别是: 1. (void)loadRequest:(NSURLRequest * ...
- 李洪强漫谈iOS开发[C语言-013]-常量
// // main.m // 09 - 常量 // // Created by 李洪强 on 16/7/17. // Copyright © 2016年 李洪强. All rights re ...
- HDU1171——Big Event in HDU(母函数)
Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...
- Android ActionBar通过Tab进行不同的Fragment之间的交换
ActionBar的使用常见于4.0系统,其Tab的使用挺广泛的. 在ActionBar中添加标签(Tabs),每个标签对应的是一个Fragment,点击不同的Tab时,就会切换到对应的Fragmen ...
- ConfigurationManager配置操作
/// <summary> /// 配置信息维护 /// </summary> public class AppConfig { public static Configura ...
- 编程之美 3.1 字符串移位包含问 复杂度(O(N*K)
分享关于编程之美3.1自己编写的代码,很简单. s2.沿着s1匹配(循环匹配,利用%Length技巧),匹配上,返回true. //BOP3.1 char src[] = "AABBCD&q ...
- jquery的smartWizard插件使用方法
jquery 的smartWizard插件常用在一些向导式的,按步骤的功能中,是的用户按照我们设定的步骤进行操作,这样一方面有较好的用户体验,可以将庞大的表格 数据分解成多个步骤,是的每个步骤的数据量 ...