HDU 4738 undirected graph point shrinking Broken Bridge // detailed question

Source: Internet
Author: User
Caocao's bridges

Question: Give an undirected graph and find the bridge with the smallest Edge Weight.

First, scale down the point directly. If there is no bridge, output-1, there is a bridge, traverse the bottom, and the update is minimal .. In minutes, I thought it was Ia .. A pair of Wa...

Pitfall: 1: If the source image is not connected, you do not need to send people! Output 0 !;

2: If the power of the bridge is 0, someone else will take the bomb and output 1!

3: There is a duplicate edge. (Calculated by multiple edges ).

Ah! Remember this lesson! Questions to be asked later

1: Consider boundary or special data! (The Edge Weight is 0! N = 1)

2: Consider source image connectivity! (The Source image is strongly connected .. Not considered to be connected at all !)

3: duplicate edge. The duplicate side of this question is calculated by the duplicate side (not one ), the data structure and algorithm I used just avoided this problem (I used the Tarjan template created by the chain forward star and undirected graph to calculate the duplicate edge in the multilateral way (the vertices of the duplicate edge must be in a BCC ), if you want to calculate the duplicate edge by one, use the chain star and the second set to record the father's vertex method Tarjan ).

The true culprit of this question Wa: you cannot forgive yourself! When I used E [I] [0], I made another low-level error !!! I used the edge! What can I do !!!

# Include <iostream> # include <stack> # include <queue> # include <cstdio> # include <cstring> using namespace STD; const int INF = 0x3f3f3f3f; const int maxv = 1005, MaxE = 1000*1003; int nume = 0; int head [maxv]; int e [MaxE] [3]; void inline Adde (int I, int J, int c) {e [nume] [0] = J; E [nume] [1] = head [I]; head [I] = nume; E [nume ++] [2] = C; E [nume] [0] = I; E [nume] [1] = head [J]; head [J] = nume; E [nume ++] [2] = C;} int dfn [maxv]; int low [maxv]; int vis [Ma XV]; int INS [maxv]; stack <int> sta; int BCC [maxv]; int numb = 0; int times = 0; int vise [MaxE]; int N, m; void Tarjan (int u) {dfn [u] = low [u] = times ++; INS [u] = 1; Sta. push (U); For (INT I = head [u]; I! =-1; I = E [I] [1]) {If (vise [I]) continue; int v = E [I] [0]; If (! Vis [v]) {vis [v] = 1; vise [I] = vise [I ^ 1] = 1; Tarjan (v ); if (low [v] <low [u]) low [u] = low [v];} else if (INS [v] & dfn [v] <low [u]) {LOW [u] = dfn [v] ;}} if (low [u] = dfn [u]) {numb ++; int cur; do {cur = Sta. top (); Sta. pop (); INS [cur] = 0; BCC [cur] = numb;} while (cur! = U) ;}} void solve () {int marks = 0; For (INT I = 1; I <= N; I ++) {If (! Vis [I]) {vis [I] = 1; Tarjan (I); marks ++;} If (marks> = 2) // Pit 1 {printf ("0 \ n"); return;} If (numb = 1) {printf ("-1 \ n"); return ;} int mins = inf; For (INT I = 1; I <= N; I ++) for (Int J = head [I]; J! =-1; j = E [J] [1]) {If (bcc [I]! = BCC [E [J] [0]) // E [J] [0] is actually written as E [I] [0]! SB !! {If (E [J] [2] <mins) Mins = E [J] [2] ;}} if (mins = 0) Mins = 1; // pitfall 2 printf ("% d \ n", mins);} void read_build () {int AA, BB, CC; For (INT I = 0; I <m; I ++) {scanf ("% d", & aa, & BB, & CC); Adde (AA, BB, CC );}} void Init () {numb = times = nume = 0; memset (vise, 0, sizeof (vise); For (INT I = 0; I <maxv; I ++) {head [I] =-1; INS [I] = dfn [I] = low [I] = BCC [I] = vis [I] = 0 ;}} int main () {While (~ Scanf ("% d", & N, & M) & (N | M) {Init (); read_build (); solve ();} return 0 ;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.