HDU 3072 SCC Intelligence System

Source: Internet
Author: User

Give a weighted graph to connect the whole graph. The points in the SCC are spent 0, so the weight of the minimum edge is reduced by the first point, then the weighted value between the two points after the point is shrunk, and the sum of these weights is the answer.

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <vector>6#include <stack>7 using namespacestd;8 9 intN, M;Ten  One Const intMAXN =50000+Ten; A  -vector<int>G[MAXN], C[MAXN]; -  thestack<int>S; - intPRE[MAXN], LOWLINK[MAXN], SCCNO[MAXN]; - intDfs_clock, scc_cnt; -  + voidDfsintu) - { +Pre[u] = Lowlink[u] = + +Dfs_clock; A s.push (u); at      for(inti =0; I < g[u].size (); i++) -     { -         intv =G[u][i]; -         if(!Pre[v]) -         { - Dfs (v); inLowlink[u] =min (Lowlink[u], lowlink[v]); -         } to         Else if(!sccno[v]) lowlink[u] =min (Lowlink[u], pre[v]); +     } -  the     if(Lowlink[u] = =Pre[u]) *     { $scc_cnt++;Panax Notoginseng          for(;;) -         { the             intx =S.top (); S.pop (); +SCCNO[X] =scc_cnt; A             if(x = = u) Break; the         } +     } - } $  $ voidFIND_SCC () - { -Dfs_clock = scc_cnt =0; thememset (PRE,0,sizeof(pre)); -memset (Sccno,0,sizeof(SCCNO));Wuyi      for(inti =0; I < n; i++)if(!Pre[i]) DFS (i); the } -  Wu intCOST[MAXN]; -  About intMain () $ { -      while(SCANF ("%d%d", &n, &m) = =2) -     { -          for(inti =0; I < n; i++) {g[i].clear (); C[i].clear (); } A          while(m--) +         { the             intU, V, D; scanf"%d%d%d", &u, &v, &d); - G[u].push_back (v); C[u].push_back (d); $         } the FIND_SCC (); the  thememset (Cost,-1,sizeof(cost)); the          for(inti =0; I < n; i++) -              for(intj =0; J < G[i].size (); J + +) in             { the                 intU = sccno[i], V =Sccno[g[i][j]]; the                 if(U = = v)Continue; About                 if(Cost[v] = =-1) Cost[v] =C[i][j]; the                 ElseCOST[V] =min (Cost[v], c[i][j]); the             } the  +         intAns =0; -          for(inti =1; I <= scc_cnt; i++)if(Cost[i]! =-1) ans + =Cost[i]; theprintf"%d\n", ans);Bayi     } the  the     return 0; -}
code June

HDU 3072 SCC Intelligence System

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.