ACM: 最近公共祖先tarjan poj 1986
来源:互联网 发布:厦门淘宝代运营 编辑:程序博客网 时间:2024/05/22 10:30
Description
Input
* Line 2+M: A single integer, K. 1 <= K<= 10,000
* Lines 3+M..2+M+K: Each line corresponds to a distance query andcontains the indices of two farms.
Output
Sample Input
7 6
1 6 13 E
6 3 9 E
3 5 7 S
4 1 3 N
2 4 20 W
4 7 2 S
3
1 6
1 4
2 6
Sample Output
13
3
36
题意: 在一棵树上, 找出多个点对之间的最短距离.
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 80005
struct node
{
}edges[MAX], qu[MAX];
int n, m;
int num1, num2;
int p[MAX], dist[MAX];
int first1[MAX], first2[MAX];
bool flag[MAX], vis[MAX];
inline void add1(int u,int v,int w)
{
}
inline void add2(int u,int v)
{
}
int find(int x)
{
}
void read_graph()
{
}
void LCA(int x)
{
}
int main()
{
//
}
-------------------------------------------------------------------------------------------------
附上一个超时的代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 100005
struct node
{
}edges[MAX*2];
int n, m;
int p[MAX][200], deep[MAX];
int first[MAX], num;
int dist[MAX];
int du[MAX], start;
inline void add(int u, int v, int w)
{
}
void read_graph()
{
}
void dfs(int u,int distance)
{
}
int LCA(int x,int y)
{
}
int main()
{
//
}
- ACM: 最近公共祖先tarjan poj 1986
- ACM: 最近公共祖先问题 图论题
- ACM: 最近公共祖先问题LCA 图论题 …
- ACM: 最长公共子序 poj 1458
- POj 2379 ACM Rank Table
- ACM: poj 1664
- ACM: poj 1050
- ACM: poj 1964
- ACM: poj 3141
- ACM: poj 1903
- ACM: 深搜 poj 2676
- ACM: 深搜题 poj 3411
- POJ 1986 Tarjan离线算法(最近公共祖先)
- poj 2186 tarjan算法
- ACM: 网络流 图论 poj 1459
- ACM: 二分法 数论题 poj 1905
- ACM: 水题 分数运算 poj 3979
- ACM: 图论题 poj 2240 (floyd + ST…
- 人工智能60周年前沿趋势交流会【转】
- ACM: 水题 分数运算 poj 3979
- ACM: 数学规律题 数论题 hdoj 1021
- ACM: 概率DP 动态规划题 poj 1322
- 基于bootstrap 的确认框
- ACM: 最近公共祖先tarjan poj 1986
- ACM: 最近公共祖先问题LCA 图论题 …
- ACM: 直接敲出LCA算法 图论题 poj …
- 柴俊理金:5、19午夜黄金,宁贵沥青操作策略
- ACM: 树的直径(两点最长距离) 图论…
- 数论: 一次同余式 (中国剩余定律)
- ACM: 二进制问题 数论题 poj 1023
- ACM: 简单题 poj 1152 (简单题也wr…
- 数论:复合数模的任意次同余式