题目
输入样例#1:
10 11 4
1 2 3 4 5 6 7 8 9 10
1 4 4
2 5 3
9 8 2
7 8 10
7 1 4
6 7 1
6 4 8
2 1 5
10 8 10
3 4 7
3 4 6
1 5 2
1 5 6
1 5 8
8 9 2
输出样例#1:
6
1
-1
8
思路:重构树 倍增找到从v出发走小于x的边可到达的点 这些点都是一个点的子树。倍增找到这个点。一个点的子树节点第k大就是 dfs+主席树模板。
1A 怔住了。。。好爽。。。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define foru(i,a,b) for(int i=a;i<=b;i++)
#define m(a,b) memset(a,b,sizeof a)
#define en '\n'
using namespace std;
typedef long long ll;
const int N=1e5+5,M=5e5+5,K=18;
template<class T>void rd(T &x)
{
x=0;int f=0;char ch=getchar();
while(ch<'0'||ch>'9') {
f|=(ch=='-');ch=getchar();}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x=f?-x:x;
return;
}
int n,m,tm;
int f[N<<1];
inline int seek(int x){
return (x==f[x])?x:(f[x]=seek(f[x]));
}
struct _Edge{
int u,v,w;}e[M];
int cmp(_Edge x,_Edge y){
return x.w<y.w;
}
struct