First, DFS is less than 2 of the deleted edge, know that can not be deleted.
It then calculates several elements within each component by checking the set.
#include <iostream>#include<cstring>#include<vector>#defineMAXN 10010#defineLL __int64using namespacestd;int inch[MAXN],VIS[MAXN],P,PA[MAXN],COU[MAXN]; LL Sum[maxn];vector<int>MP[MAXN];voidDfsintu) { inti; Vis[u]=1; for(i=0; I<mp[u].size (); i++) { inch[u]--; inch[mp[u][i]]--; if(!vis[mp[u][i]]&&inch[mp[u][i]]<2) DFS (Mp[u][i]); }}intFind (intx) { if(x!=pa[x]) pa[x]=Find (pa[x]); returnpa[x];}intMain () {inti,j,t,q; CIN>>T; while(t--) {cin>>p>>Q; for(i=0; i<=p;i++) {mp[i].clear (); Pa[i]=i; Cou[i]=1; Vis[i]=0; inch[i]=0; } for(i=1; i<=p;i++) {cin>>Sum[i]; } while(q--) { intx, y; CIN>>x>>y; Mp[x].push_back (y); Mp[y].push_back (x); inch[x]++; inch[y]++; } intFlag; while(1) {flag=0; for(i=1; i<=p;i++) { if(!vis[i]&&inch[i]<2) {flag=1; Break; } } if(flag==0) Break; for(i=1; i<=p;i++) { if(!vis[i]&&inch[i]<2) {DFS (i); } } } /*for (i=1;i<=p;i++) {printf ("%d", in[i]); } printf ("\ n"); For (I=0;i<mp[1].size (); i++) {printf ("%d", mp[1][i]); } printf ("\ n");*/ for(i=1; i<=p;i++) { if(Vis[i])Continue; intfx=Find (i); intnum=mp[i].size (); //printf ("%d", FX); for(j=0; j<num;j++) { if(!vis[mp[i][j]]&&inch[mp[i][j]]>=2) { intfy=Find (Mp[i][j]); if(FX==FY)Continue; //printf ("%d", mp[i][j]);pa[fy]=FX; SUM[FX]+=Sum[fy]; COU[FX]+=Cou[fy]; //printf ("%d", Cou[fx]); } } //printf ("\ n");} LL ans=0; for(i=1; i<=p;i++) { if(pa[i]==i&&!vis[i]&&cou[i]%2&&cou[i]!=1) { //printf ("%i64d", Sum[i]);ans+=Sum[i]; } } //puts ("");printf"%i64d\n", ans); }}/*9 2 3 4 5 6 7 8 (9)*/
hdu5438 dfs+ and check the Changchun network race