记录编号 |
117356 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[USACO Open09] 捉迷藏 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.054 s |
提交时间 |
2014-08-29 15:49:37 |
内存使用 |
0.62 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
int n,r;
vector <int> Edge[20010];
int dist[20010];
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="hideseek";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d%d",&n,&r);
For(i,1,n)
Edge[i].clear();
int s,e;
For(i,1,r)
{
scanf("%d%d",&s,&e);
Edge[s].push_back(e);
Edge[e].push_back(s);
}
memset(dist,-1,sizeof(dist));
dist[1]=0;
queue <int>Q;
Q.push(1);
while (!Q.empty())
{
int now=Q.front();Q.pop();
int siz=Edge[now].size()-1;
int x;
For(i,0,siz)
{
x=Edge[now][i];
if (dist[x]!=-1) continue;
dist[x]=dist[now]+1;
Q.push(x);
}
}
int mindis=0,minn,cnt=0;
For(i,2,n)
{
if (dist[i]>mindis)
mindis=dist[i],cnt=0,minn=i;
if (dist[i]==mindis)
cnt++;
}
printf("%d %d %d\n",minn,mindis,cnt);
#ifdef DEBUG
clock_t End_Time=clock();
printf("\n\nTime Used: %.4lfms\n",End_Time-Start_Time);
#endif
return 0;
}
//================fuction code====================