int n, m, a[MAXN]; structGraph { structEdge { int v, nxt; }e[MAXM]; int head[MAXN], cnt; voidaddedge(int u, int v){ e[++cnt] = {v, head[u]}; head[u] = cnt; } }G1, G2;
voidtarjan(int u){ dfn[u] = low[u] = ++_dfn; stk[++top] = u; ins[u] = 1; for(int i = G1.head[u]; i; i = G1.e[i].nxt) { int v = G1.e[i].v; if(!dfn[v]) { tarjan(v); low[u] = min(low[u], low[v]); } elseif(ins[v]) { low[u] = min(low[u], dfn[v]); } } if(dfn[u] == low[u]) { ++_scc; int t; do { t = stk[top--]; ins[t] = 0; scc[t] = _scc; scc_sum[_scc] += a[t]; }while(t != u); } }
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; G1.addedge(u, v); } for(int i = 1; i <= n; i++) if(!dfn[i]) tarjan(i); for(int u = 1; u <= n; u++) for(int i = G1.head[u]; i; i = G1.e[i].nxt) { int v = G1.e[i].v; if(scc[u] == scc[v]) continue; G2.addedge(scc[u], scc[v]); deg[scc[v]]++; } hd = 1; tl = 0; for(int i = 1; i <= _scc; i++) if(deg[i] == 0) { que[++tl] = i; f[i] = scc_sum[i]; } while(hd <= tl) { int u = que[hd++]; for(int i = G2.head[u]; i; i = G2.e[i].nxt) { int v = G2.e[i].v; f[v] = max(f[v], f[u] + scc_sum[v]); if(--deg[v] == 0) que[++tl] = v; } } int ans = 0; for(int i = 1; i <= _scc; i++) ans = max(ans, f[i]); cout << ans << '\n'; return0; }
constexprint MAXN = 2e4 + 5; constexprint MAXM = 2e5 + 5; int n, m; structEdge { int v, nxt; }e[MAXM]; int head[MAXN], cnt; voidaddedge(int u, int v){ e[++cnt] = {v, head[u]}; head[u] = cnt; }
int dfn[MAXN], low[MAXN], _dfn, cut[MAXN];
voidtarjan(int u, int fa, int rt){ dfn[u] = low[u] = ++_dfn; int ch = 0; for(int i = head[u]; i; i = e[i].nxt) { int v = e[i].v; if(v == fa) continue; if(!dfn[v]) { ch++; tarjan(v, u, rt); low[u] = min(low[u], low[v]); if(low[v] >= dfn[u]) { if(u != rt || ch >= 2) cut[u] = 1; } } else low[u] = min(low[u], dfn[v]); } }
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; addedge(u, v); addedge(v, u); } for(int i = 1; i <= n; i++) if(!dfn[i]) tarjan(i, 0, i); int ans = 0; for(int i = 1; i <= n; i++) if(cut[i]) ++ans; cout << ans << '\n'; for(int i = 1; i <= n; i++) if(cut[i]) cout << i << ' '; cout << '\n'; return0; }