#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<stack> #include<vector> #include<queue> #define MAXN (100000 + 5) #define INF (1000000000 + 5) usingnamespace std; structedg { int from, to, cost, next, bh; } b[MAXN]; int n, m, cntb, g[MAXN], dfn[MAXN], low[MAXN], cntdfn, du[MAXN], rnk[MAXN]; bool ins[MAXN]; stack<int> gary; vector<int> outp; queue<int> q; booltarjan(int dq, int x){ gary.push(dq); ins[dq] = true; dfn[dq] = low[dq] = ++cntdfn; bool re = false; for (int i = g[dq]; i; i = b[i].next) { if (b[i].cost <= x) continue; if (!dfn[b[i].to]) re |= tarjan(b[i].to, x), low[dq] = min(low[dq], low[b[i].to]); elseif (ins[b[i].to]) low[dq] = min(low[dq], dfn[b[i].to]); if (re) returntrue; } if (dfn[dq] == low[dq]) { if (gary.top() != dq) returntrue; while (gary.top() != dq) ins[gary.top()] = false, gary.pop(); gary.pop(); ins[dq] = false; } returnfalse; } voidef(){ int le = 0, ri = INF, ans = INF; while (le < ri) { int mi = (le + ri) >> 1; memset(dfn, 0, sizeof(dfn)); memset(low, 0, sizeof(low)); cntdfn = 0; bool ok = false; for (int i = 1; i <= n && !ok; i++) if (!dfn[i]) ok = tarjan(i, mi); if (ok) le = mi + 1; else ans = ri = mi; } printf("%d ", ans); if (!ans) { puts("0"); return ; } for (int i = 1; i <= m; i++) if (b[i].cost > ans) ++du[b[i].to]; for (int i = 1; i <= n; i++) if (!du[i]) q.push(i), rnk[i] = ++rnk[0]; while (!q.empty()) { int dq = q.front(); q.pop(); for (int i = g[dq]; i; i = b[i].next) if (b[i].cost > ans) { --du[b[i].to]; if (!du[b[i].to]) rnk[b[i].to] = ++rnk[0], q.push(b[i].to); } } for (int i = 1; i <= m; i++) if (b[i].cost <= ans && rnk[b[i].from] > rnk[b[i].to]) outp.push_back(b[i].bh); printf("%d\n", outp.size()); for (int i = 0; i < outp.size(); i++) printf("%d ", outp[i]); } voidadn(int from, int to, int cost, int bh){ b[++cntb].next = g[from]; b[cntb].from = from, b[cntb].to = to, b[cntb].cost = cost, b[cntb].bh = bh; g[from] = cntb; } intmain(){ scanf("%d%d", &n, &m); for (int i = 1, srx, sry, src; i <= m; i++) scanf("%d%d%d", &srx, &sry, &src), adn(srx, sry, src, i); ef(); return0; }
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> #include<algorithm> #define MAXN (500000 + 5) #define MAXL (20 + 2) #define LS(dq) ((dq) << 1) #define RS(dq) (((dq) << 1) | 1) usingnamespace std; structxxj { int zh[MAXL]; xxj() { memset(zh, 0, sizeof(zh)); } voidins(int x){ for (int i = MAXL - 1; i >= 0; i--) if (x & (1 << i)) { if (!zh[i]) { zh[i] = x; break; } x ^= zh[i]; } } intmax(){ int re = 0; for (int i = MAXL - 1; i >= 0; i--) if ((re ^ zh[i]) > re) re ^= zh[i]; return re; } }; structnode { int le, ri; xxj zh; } b[MAXN << 2]; int n, a[MAXN]; xxj uni(xxj re, const xxj y){ for (int i = MAXL - 1; i >= 0; i--) re.ins(y.zh[i]); return re; } voidjs(int dq, int le, int ri){ b[dq].le = le, b[dq].ri = ri; for (int i = le; i <= ri; i++) b[dq].zh.ins(a[i]); if (le == ri) return ; int mi = (le + ri) >> 1; js(LS(dq), le, mi), js(RS(dq), mi + 1, ri); } xxj cx(int dq, int le, int ri){ if (b[dq].le == le && b[dq].ri == ri) return b[dq].zh; int mi = (b[dq].le + b[dq].ri) >> 1; if (le > mi) returncx(RS(dq), le, ri); elseif (ri <= mi) returncx(LS(dq), le, ri); elsereturnuni(cx(LS(dq), le, mi), cx(RS(dq), mi + 1, ri)); } inlineintread(){ int re = 0; char x = 0; while (x < '0' || x > '9') x = getchar(); while (x >= '0' && x <= '9') re = re * 10 + x - '0', x = getchar(); return re; } intmain(){ n = read(); for (int i = 1; i <= n; i++) a[i] = read(); js(1, 1, n); int q; q = read(); for (int i = 1, srx, sry; i <= q; i++) srx = read(), sry = read(), printf("%d\n", cx(1, srx, sry).max()); return0; }