1 2 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
| ##include "bits/stdc++.h" using namespace std;
const int N = 1e6 + 10, M = 2e6 + 10; int n, m; struct Edge { int u, v, w; bool operator < (const Edge &rhs) const { return w > rhs.w; } }E[M]; vector<int> g[N]; int val[N], f[N], cnt; int dep[N], son[N], fa[N], siz[N], top[N], dfn[N], tim;
void dfs1(int u, int par) { dep[u] = dep[fa[u] = par] + (siz[u] = 1); for(auto v : g[u]) { if(v == par) continue; dfs1(v, u); siz[u] += siz[v]; if(!son[u] siz[v] > siz[son[u]]) son[u] = v; } }
void dfs2(int u, int topf) { dfn[u] = ++tim; top[u] = topf; if(!son[u]) return ; dfs2(son[u], topf); for(auto v : g[u]) { if(v == fa[u] v == son[u]) continue; dfs2(v, v); } }
int lca(int x, int y) { while(top[x] != top[y]) { if(dep[top[x]] < dep[top[y]]) swap(x, y); x = fa[top[x]]; } return dep[x] < dep[y] ? x : y; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void EX_Kruskal() { cnt = n; for(int i = 1;i < (n << 1); i++) f[i] = i; sort(E + 1, E + m + 1); for(int i = 1;i <= m; i++) { int u = find(E[i].u); int v = find(E[i].v); if(u == v) continue; val[++cnt] = E[i].w; f[u] = f[v] = cnt; g[u].emplace_back(cnt); g[cnt].emplace_back(u); g[v].emplace_back(cnt); g[cnt].emplace_back(v); if(cnt == (n << 1) - 1) break; } int rt = find(1); dfs1(rt, 0); dfs2(rt, rt); }
bool cmp(int x, int y) { return dfn[x] < dfn[y]; }
void solve() { int _; scanf("%d%d%d",&n,&m,&_); for(int i = 1;i <= m; i++) { int u, v, w; scanf("%d%d%d",&u,&v,&w); E[i] = {u, v, w}; } EX_Kruskal(); int lastans = 0; while(_--) { int k; scanf("%d",&k); vector<int> a(k); for(int i = 0;i < k; i++) scanf("%d",&a[i]), a[i] ^= lastans; lastans = 0; sort(a.begin(), a.end(), cmp); for(int i = 1;i < k; i++) { lastans = max(lastans, val[lca(a[i], a[i - 1])]); } printf("%d\n",lastans); } }
signed main() { solve(); }
|