文章分类 - LCA和RMQ问题
摘要:求任意两点之间的最短距离,不连通的话输出不连通。#include <stdio.h>#include <string.h>#include <vector>using namespace std;#define MAXN 10001#define MAXQ 1000000int N,bcnt,father[MAXN],ance[MAXN],dis[MAXN],r...
阅读全文
摘要://1375MS,超慢啊:#include <stdio.h>#include <string.h>#include <vector>using namespace std;#define MAXN 50005#define MAXQ 10001int N,father[MAXN],ance[MAXN],dis[MAXN],res[MAXQ];struct EN...
阅读全文
摘要:c++递归的话会爆栈,自编写非递归46MSG++递归不会爆78MS,tragedy!!!#include <stdio.h>#include <vector>using namespace std;#define MAXN 40001#define MAXQ 201int N,father[MAXN],ance[MAXN],dis[MAXN],res[MAXQ];struc...
阅读全文
摘要://方法1,并查集+tarjan,离线的LCA算法,32MS#include <stdio.h>#include <string.h>#include <vector>using namespace std;#define MAXN 10005int N,father[MAXN],ance[MAXN];vector<int> adjlist[MAXN...
阅读全文
摘要://RMQ做法,线段树竟然会快些,靠啊#include <stdio.h>#include <math.h>#define MAXN 50001#define MAXLOG 16int N,a[MAXN],maxst[MAXN][MAXLOG],minst[MAXN][MAXLOG];inline int Max(int a,int b){ return a>b?a:...
阅读全文
浙公网安备 33010602011771号