Caocao's Bridges hdu-4738
阿新 • • 發佈:2020-12-10
題面
題解
縮點, 坑點在最小邊為0是, 你至少用1個人去炸橋
程式碼
int n, m, _, k; int h[N], ne[M << 1], to[M << 1], co[M << 1], tot; int dfn[N], low[N], df, ans; void add(int u, int v, int c) { ne[++tot] = h[u]; to[h[u] = tot] = v; co[tot] = c; } void tarjan(int x, int e) { dfn[x] = low[x] = ++df; for (int i = h[x]; i; i = ne[i]) { int y = to[i]; if (!dfn[y]) { tarjan(y, i); umin(low[x], low[y]); if (dfn[x] < low[y]) umin(ans, co[i]); } else if (i != (e ^ 1)) umin(low[x], dfn[y]); } } int main() { IOS; while (cin >> n >> m, n || m) { memset(dfn, 0, sizeof dfn); df = 0; memset(h, 0, sizeof h); tot = 1; rep (i, 1, m) { int u, v, c; cin >> u >> v >> c; add(u, v, c); add(v, u, c); } ans = 1e9; tarjan(1, -1); umax(ans, 1); rep (i, 2, n) if (!dfn[i]) { ans = 0; break; } cout << (ans == 1e9 ? -1 : ans) << '\n'; } return 0; }