| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 
 | 
 
 #include <bits/stdc++.h>
 
 inline char read() {
 static const int IN_LEN = 1000000;
 static char buf[IN_LEN], *s, *t;
 s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin) : 0;
 return s == t ? -1 : *s++;
 }
 
 template<class T>
 inline void read(T &x) {
 static char c;
 static bool iosig;
 for (c = read(), iosig = false; !isdigit(c); c = read()) {
 if (c == -1) return;
 c == '-' ? iosig = true : 0;
 }
 for (x = 0; isdigit(c); c = read())
 x = (x + (x << 2) << 1) + (c ^ '0');
 iosig ? x = -x : 0;
 }
 
 const int OUT_LEN = 1000000;
 
 char obuf[OUT_LEN], *oh = obuf;
 
 inline void print(char c) {
 oh == obuf + OUT_LEN ? (fwrite(obuf, 1, OUT_LEN, stdout), oh = obuf) : 0;
 *oh++ = c;
 }
 
 template<class T>
 inline void print(T x) {
 static int buf[30], cnt;
 if (x == 0) {
 print('0');
 } else {
 if (x < 0) print('-'), x = -x;
 for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
 while (cnt) print((char)buf[cnt--]);
 }
 }
 
 inline void flush() {
 fwrite(obuf, 1, oh - obuf, stdout);
 }
 
 namespace UnionFindSet {
 
 const int MAXN = 500005;
 
 int fa[MAXN], f[MAXN], rank[MAXN], dep[MAXN];
 int cnt = 0;
 
 inline int get(int x) {
 static int st[100], top;
 while (x != fa[x]) st[++top] = x, x = fa[x];
 while (top) dep[st[top]] = dep[fa[st[top--]]] + 1;
 return x;
 }
 
 inline void put(int x,int y) {
 if ((x = get(x)) != (y = get(y))) {
 rank[x] > rank[y] ? (std::swap(x, y), 0) : 0;
 fa[x] = y, f[x] = ++cnt, rank[y] += rank[x];
 } else {
 cnt++;
 }
 }
 
 inline int ask(int x,int y) {
 register int fx = get(x), fy = get(y);
 if (fx ^ fy) return 0;
 register int rtn = 0;
 while (x ^ y) {
 dep[x] > dep[y] ? (rtn = std::max(rtn, f[x]), x = fa[x])
 : (rtn = std::max(rtn, f[y]), y = fa[y]);
 }
 return rtn;
 }
 
 int opt, lastans, tmp;
 
 inline void solve() {
 register int n, m;
 read(n), read(m);
 
 for (register int i = 1; i <= n; i++) fa[i] = i, rank[i] = 1;
 
 for (register int i = 1, x, y; i <= m; i++) {
 read(opt), read(x), read(y);
 if (opt) print(tmp = ask(x ^ lastans, y ^ lastans)), print('\n'), lastans = tmp;
 else put(x ^ lastans, y ^ lastans);
 }
 }
 
 }
 
 int main() {
 UnionFindSet::solve();
 flush();
 return 0;
 }
 
 |