HDU 3072 Intelligence System

Posted 一蓑烟雨任生平

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 3072 Intelligence System相关的知识,希望对你有一定的参考价值。

Intelligence System

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2890    Accepted Submission(s): 1258

Problem Description
After a day, ALPCs finally complete their ultimate intelligence system, the purpose of it is of course for ACM ... ... 
Now, kzc_tc, the head of the Intelligence Department (his code is once 48, but now 0), is sudden obtaining important information from one Intelligence personnel. That relates to the strategic direction and future development of the situation of ALPC. So it need for emergency notification to all Intelligence personnel, he decides to use the intelligence system (kzc_tc inform one, and the one inform other one or more, and so on. Finally the information is known to all).
We know this is a dangerous work. Each transmission of the information can only be made through a fixed approach, from a fixed person to another fixed, and cannot be exchanged, but between two persons may have more than one way for transferring. Each act of the transmission cost Ci (1 <= Ci <= 100000), the total cost of the transmission if inform some ones in our ALPC intelligence agency is their costs sum. 
Something good, if two people can inform each other, directly or indirectly through someone else, then they belong to the same branch (kzc_tc is in one branch, too!). This case, it’s very easy to inform each other, so that the cost between persons in the same branch will be ignored. The number of branch in intelligence agency is no more than one hundred.
As a result of the current tensions of ALPC’s funds, kzc_tc now has all relationships in his Intelligence system, and he want to write a program to achieve the minimum cost to ensure that everyone knows this intelligence.
It‘s really annoying!
 
Input
There are several test cases. 
In each case, the first line is an Integer N (0< N <= 50000), the number of the intelligence personnel including kzc_tc. Their code is numbered from 0 to N-1. And then M (0<= M <= 100000), the number of the transmission approach.
The next M lines, each line contains three integers, X, Y and C means person X transfer information to person Y cost C. 
 
Output
The minimum total cost for inform everyone.
Believe kzc_tc’s working! There always is a way for him to communicate with all other intelligence personnel.
 
Sample Input
3 3 0 1 100 1 2 50 0 2 100 3 3 0 1 100 1 2 50 2 1 100 2 2 0 1 50 0 1 100
 
Sample Output
150 100 50
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  3069 3077 3070 3071 3073 
 
 
#include<iostream>
#include<cstdio> 
#include<cstring>
#include<algorithm>
#define LL int
#define MAXN 100000+15
using namespace std;
LL n,m,tot,tim,top,sumcol,ans,bns,cap[MAXN];
LL to[MAXN],from[MAXN],net[MAXN],col[MAXN],val[MAXN];
LL dfn[MAXN],low[MAXN],vis[MAXN],stack[MAXN],visstack[MAXN];
inline void add(LL u,LL v,LL w){
    to[++tot]=v;net[tot]=from[u];from[u]=tot;cap[tot]=w;
}
inline void tarjin(LL now){
    low[now]=dfn[now]=++tim;
    stack[++top]=now;
    visstack[now]=1;
    vis[now]=1;
    for(LL i=from[now];i;i=net[i])
        if(visstack[to[i]])
            low[now]=min(low[now],dfn[to[i]]);
        else if(!vis[to[i]]){
            tarjin(to[i]);
            low[now]=min(low[now],low[to[i]]);
        }
    if(dfn[now]==low[now]){
        sumcol++;
        col[now]=sumcol;
        while(stack[top]!=now){
            col[stack[top]]=sumcol;
            visstack[stack[top]]=0;
            top--;
        }
        visstack[now]=0;
        top--;
    } 
}
int main(){
    while(scanf("%d%d",&n,&m)!=EOF){
        top=0;tot=0;sumcol=0;tim=0;
        ans=0;bns=0;
        memset(to,0,sizeof(to));
        memset(low,0,sizeof(low));
        memset(dfn,0,sizeof(dfn));
        memset(vis,0,sizeof(vis));
        memset(col,0,sizeof(col));
        memset(net,0,sizeof(net));    
        memset(from,0,sizeof(from));
        memset(val,0x3f,sizeof(val));
        memset(stack,0,sizeof(stack));
        memset(visstack,0,sizeof(visstack));
        for(LL i=1;i<=m;i++){
            LL a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            add(a+1,b+1,c);
        }
        for(LL i=1;i<=n;i++)
            if(!vis[i])    tarjin(i);
        for(LL i=1;i<=n;i++)
            for(int j=from[i];j;j=net[j])
                if(col[to[j]]!=col[i])
                    val[col[to[j]]]=min(val[col[to[j]]],cap[j]);
        long long ans=0;
        for(LL i=1;i<=sumcol;i++)
        if(val[i]!=1061109567)
            ans+=1ll*val[i];
        printf("%lld\n",ans);
    }
}

 

以上是关于HDU 3072 Intelligence System的主要内容,如果未能解决你的问题,请参考以下文章

hdu 3072 Intelligence System

Intelligence System HDU - 3072(强连通分量)

HDU - 3072 Intelligence System

HDU3072 Intelligence System

hdu3072 Intelligence System (最小树形图?)

HDU 3072 Intelligence System(强连通分量,缩点)