spoj 1437
自己暴了一下不过 转一个 bfs...
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#define maxn 10010
using namespace std; struct node
{
int v,dist;
node() {}
node(int _v, int _dist)
{
v = _v;
dist = _dist;
}
} aux;
bool visited[maxn];
vector<int> L[maxn]; node search(int v)
{
node ans = node(v,0);
queue<node> Q;
Q.push(node(v,0));
memset(visited,false,sizeof(visited));
visited[v] = true;
while(!Q.empty())
{
aux = Q.front();
Q.pop();
ans = aux;
for(int i = L[aux.v].size()-1; i >= 0; --i)
{
if(visited[L[aux.v][i]])
continue;
visited[L[aux.v][i]] = true;
Q.push(node(L[aux.v][i], aux.dist+1));
}
}
return ans;
} int main()
{
int N,u,v;
scanf("%d",&N);
for(int i = 1; i < N; ++i)
{
scanf("%d%d",&u,&v);
L[u].push_back(v), L[v].push_back(u);
}
printf("%d\n",search(search(1).v).dist);
return 0;
}
spoj 1437的更多相关文章
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- SPOJ bsubstr
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...
- 【SPOJ 7258】Lexicographical Substring Search
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...
- 【SPOJ 1812】Longest Common Substring II
http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...
- 【SPOJ 8222】Substrings
http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...
- SPOJ GSS2 Can you answer these queries II
Time Limit: 1000MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description Being a ...
随机推荐
- Unity3D除了在编辑器里,怎么用代码给一个Texture类型的变量赋值
resource.load上来一张贴图就行. using UnityEngine; using System.Collections; public class example : MonoBehav ...
- hive 未初始化元数据库报错
启动hive-metastore和hive-server2 用beeline连接hive报错 [root@node04 hive]# beeline Beeline version 0.13.1-cd ...
- Windows7 下配置添加ASP功能
按照如下顺序添加 1.控制面板-程序-打开或关闭Windows功能 2.Internet信息服务-万维网服务-应用程序开发功能 3.勾选ASP 和ASP.net选项 确定后安装完毕即可支持.
- Centos6.5 64linux系统基础优化(一)
1 SecureCRT配色方案 http://blog.csdn.net/zklth/article/details/8937905 2 32位和64位Centos linux系统的区别及实际查看 ...
- 第四篇、CocoaPods 镜像的更新 原来的淘宝镜像已经不再更新
在开发应用,我们常常使用cocoaPods来管理第三方框架,但是原来的淘宝的镜像不更新了 新的镜像地址:https://gems.ruby-china.org/
- windows下配置Apache2.4一些改变
下载地址: http://www.apachelounge.com/download/http://www.apachehaus.com/cgi-bin/download.plx Apache更新到2 ...
- 【原】GO 语言常见错误
1. Scan error on column index 4: converting string "" to a int: strconv.ParseInt: parsing ...
- IOCP模型总结(转)
IOCP模型总结(转) IOCP(I/O Completion Port,I/O完成端口)是性能最好的一种I/O模型.它是应用程序使用线程池处理异步I/O请求的一种机制.在处理多个并发的异步I/O请求 ...
- linux gcc 和 g++ 编译
gcc编译 gcc -o test.out test.c g++ 编译 g++ -o test.out test.cpp
- 用一天的时间学习Java EE中的SSH框架
首先说明一下,本人目前主要从事.NET领域的工作,但对于C++.Java.OC等语言也略知一二,周末闲来无事,特花费一天的时间学习了一下Java中的SSH框架,希望把学习过程中的心得体会与园友们进行分 ...