其他分享
首页 > 其他分享> > Caocao's Bridges hdu-4738

Caocao's Bridges hdu-4738

作者:互联网

题面

传送门

题解

缩点, 坑点在最小边为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;
}

标签:Bridges,hdu,int,rep,memset,Caocao,dfn,ans,sizeof
来源: https://www.cnblogs.com/2aptx4869/p/14113554.html