1170: Wire Is So Expensive

本文介绍了一种用于计算连接多个城镇所需的最小电线长度的算法。背景是一家专门通过电线连接城镇的公司面临着电线价格日益上涨的问题,需要计算最少的电线长度来实现城镇间的有效连接。

1170: Wire Is So Expensive


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K620259Standard

1st Jilin University ACM International Collegiate Programming Contest

Assume you are working for ACM(Andrew Communication Management) company. This company is specialized to make towns connected by wire. We all know that wire can only be put along roads. But in recent years, the price of per metre of wire is going higher and higher. So the company needs to know what is the minimal length of wire they have to prepare to connect several towns together in order that each town can connect to another by wire. You are given a map of N towns and how they are connected by roads. Your task is to write a program to determine the minimal length of wire.

Input Specification

This problem contains M maps. The first line of input is an integer M. Then follow M maps' descriptions, each of which is described below:

N
a1 b1 c1
a2 b2 c2
...
an bn cn
0 0 0

where N(1<=N<=20) is the number of towns(1, 2, ... N) and ai, bi, ci means there is a road between towns ai and bi(1<=ai, bi<=N) with length ci(1<=ci<=100). Three 0s mark the end of a map. All the numbers will be integers.

Output Specification

For each map, you should print a line containing the minimal length of wire the company has to prepare.

Sample Input

1
5
1 2 3
1 4 5
2 3 6
2 4 2
2 5 6
3 5 5
4 5 8
0 0 0

Sample Output

16
#include<stdio.h>
#include<string.h>
int inf=(1<<31)-2;
int main()
{
    int c[101][101];
    int ll;
    scanf("%d",&ll);
    while(ll--)
    {
        int n,i,j;
        scanf("%d",&n);
        int ai,bi,ci;
        memset(c,12,sizeof(c));
        while(1)
        {
            scanf("%d%d%d",&ai,&bi,&ci);
            if(ai==0&&bi==0&&ci==0) break;
            if(ci<c[ai-1][bi-1]) c[ai-1][bi-1]=c[bi-1][ai-1]=ci;
        }
        int vis[100],lowc[100];
        memset(vis,0,sizeof(vis));
        int minc,res=0;
        int p=0;
        vis[0]=1;
        for(i=0;i<n;i++) lowc[i]=c[0][i];
        for(j=1;j<n;j++)
        {
            minc=inf;p=0;
            for(i=0;i<n;i++)
            {
                if(vis[i]==0&&minc>lowc[i])
                {
                    minc=lowc[i];
                    p=i;
                }
            }
            if(minc==inf) break;
            vis[p]=1;res+=minc;
            for(i=0;i<n;i++)
            {
                if(vis[i]==0&&lowc[i]>c[p][i])  lowc[i]=c[p][i];
            }
        }
        printf("%d/n",res);
    }
    return 0;
}

Systems using Prestera® devices are characterized by usage of multiple high-speed ports. The testing equipment for high-speed ports is very expensive and is not always available for a large number of ports. Marvell supports a mechanism enabling basic testing and debug of devices without external equipment. However, this feature is not for production purposes. The devices incorporate internal Packet Generator units that can generate standard Layer 2 packets, though wire speed is not guaranteed. The built-in MIB counters are used to complete the required testing. The following sections describe the Packet Generator functionality and the relevant CPSS APIs. Flow for Lion2 and Gen5 Devices Use the Packet Generator as follows: Connect the port to the Packet Generator and configure the packet to be sent by calling cpssDxChDiagPacketGeneratorConnectSet. Start the transmission by calling cpssDxChDiagPacketGeneratorTransmitEnable. If a single burst transmit mode is used: Check the transmission status by calling cpssDxChDiagPacketGeneratorBurstTransmitStatusGet. If continuous transmit mode is used, stop transmission by calling cpssDxChDiagPacketGeneratorTransmitEnable. Verify the receiving side by using the port's MAC MIB counter. After you finish working with the Packet Generator, disconnect it from the port by changing the port connect filed to GT_False by calling cpssDxChDiagPacketGeneratorConnectSetand set the port back to normal operation. Flow for Gen6 Devices Use the Packet Generator as follows: Enable port as PG and set stream by: cpssDxChDiagPacketGeneratorConnectSet devNum portNum connect true. Isolate all ports in the same DP as the PG port, so all traffic sent to these ports is dropped: GT_STATUS cpssDxChBrgEgrFltPortLinkEnableSet ( IN GT_U8 devNum, IN GT_PHYSICAL_PORT_NUM portNum- Per port IN CPSS_DXCH_BRG_EGR_FLT_PORT_LINK_STATUS_ENT portLinkStatusState ) CPSS_DXCH_BRG_EGR_FLT_PORT_LINK_STATUS_FORCE_LINK_DOWN_E NOTE: Do not use the Tx functionality of the PG port or any of the ports in the Data Path, or in other words, do not use any of these ports for regular egress. Start traffic by cpssDxChDiagPacketGeneratorTransmitEnable. Disable PG on port: Call cpssDxChDiagPacketGeneratorConnectSet devNum portNum connect false. Link down port. Link up port.讲述一下该功能
最新发布
09-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值