今天AK啦,而且是rank1,真是超开心,这是弱菜的人生第一次AK
T1并查集,BZOJ 冷战
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> tmp;
const int MAXN = 200000 + 10;
int n, m, timer, sz[MAXN], fa[MAXN], tim[MAXN], dep[MAXN];
struct Un{ int x, y; } U[MAXN];
void init( ) { for( register int i = 1; i <= n; i++ ) sz[i] = 1, fa[i] = i; }
void Union( int x, int y ) {
while( fa[x] != x ) x = fa[x];
while( fa[y] != y ) y = fa[y];
if( sz[x] > sz[y] ) swap( x, y );
fa[x] = y; tim[x] = ++timer;
sz[y] += sz[x];
}
void get_dep( int x ) {
if( fa[x] == x ) return;
get_dep( fa[x] );
dep[x] = dep[fa[x]] + 1;
}
int query( int x, int y ) {
get_dep(x); get_dep(y);
int tmp = 0;
if( dep[x] < dep[y] ) swap( x, y );
while( dep[x] > dep[y] && x != y ) tmp = max( tmp, tim[x] ), x = fa[x];
while( x != y ) { tmp = max( tmp, max( tim[x], tim[y] ) ); x = fa[x]; y = fa[y]; }
return tmp;
}
int main( ) {
freopen( "union.in", "r", stdin );
freopen( "union.out", "w", stdout );
scanf( "%d%d", &n, &m );
init( ); int x, y;
for( register int i = 1; i <= n - 1; i++ ) {
scanf(