Network()

Network

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
Total Submission(s) : 17   Accepted Submission(s) : 8
Special Judge

Problem Description

Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each worker of the company must have access to the whole network, each hub must be accessible by cables from any other hub (with possibly some intermediate hubs).
Since cables of different types are available and shorter ones are cheaper, it is necessary to make such a plan of hub connection, that the maximum length of a single cable is minimal. There is another problem not each hub can be connected to any other one because of compatibility problems and building geometry limitations. Of course, Andrew will provide you all necessary information about possible hub connections.
You are to help Andrew to find the way to connect hubs so that all above conditions are satisfied.

Input

The first line of the input contains two integer numbers: N - the number of hubs in the network (2 <= N <= 1000) and M - the number of possible hub connections (1 <= M <= 15000). All hubs are numbered from 1 to N. The following M lines contain information about possible connections - the numbers of two hubs, which can be connected and the cable length required to connect them. Length is a positive integer number that does not exceed 106. There will be no more than one way to connect two hubs. A hub cannot be connected to itself. There will always be at least one way to connect all hubs.

Output

Output first the maximum length of a single cable in your hub connection plan (the value you should minimize). Then output your plan: first output P - the number of cables used, then output P pairs of integer numbers - numbers of hubs connected by the corresponding cable. Separate numbers by spaces and/or line breaks.

Sample Input

4 6 1 2 1 1 3 1 1 4 2 2 3 1 3 4 1 2 4 1

Sample Output

1 4 1 2 1 3 2 3 3 4

题解:

一:找最小生成树的最小权值;

二:生成这个数的数据组数;

三:输出这些数据;

这题样例是错的,无语;

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 #define MAX(x,y) (x>y?x:y)
 6 const int MAXN=15010;
 7 struct Node{
 8     int s,e,c;
 9 };
10 int cmp(Node a,Node b){
11     return a.c<b.c;
12 }
13 Node dt[MAXN];
14 int pre[1010];
15 int pt[MAXN],k,flot,as;
16 int find(int x){
17     return pre[x]= x==pre[x]?x:find(pre[x]);
18 }
19 void add(int a,int b){
20     pt[k++]=a;pt[k++]=b;
21 }
22 void initial(){
23     memset(pre,0,sizeof(pre));
24     k=0;flot=1;
25     as=-1;
26 }
27 void merge(Node a){
28         int f1,f2;
29     if(!pre[a.s])pre[a.s]=a.s;
30     if(!pre[a.e])pre[a.e]=a.e;
31     f1=find(a.s);f2=find(a.e);
32     if(f1!=f2){
33         add(a.s,a.e);
34         flot++;
35         as=MAX(as,a.c);
36         pre[f1]=f2;
37     }
38 }
39 int main(){int N,M;
40     while(~scanf("%d%d",&N,&M)){
41         initial();
42         for(int i=0;i<M;i++){
43             scanf("%d%d%d",&dt[i].s,&dt[i].e,&dt[i].c);
44         }
45         sort(dt,dt+M,cmp);
46         for(int i=0;i<M;i++){
47             merge(dt[i]);
48         }
49         printf("%d\n%d\n",as,k/2);
50         for(int i=0;i<k;i+=2){
51             printf("%d %d\n",pt[i],pt[i+1]);
52         }
53     }
54     return 0;
55 }
时间: 2024-10-12 16:05:02

Network()的相关文章

[转]VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT

转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/03/15/1985084.html VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式).要想在网络管理和维护中合理应用它们,你就应该先了解一下这三种工作模式. 1.bridged(桥接模式) 在这种模式下,VMWare虚拟出来的操作系统就像是局域网中的一台独立的主机,它可以访问网内任何一台机器.在桥接模式下

Corporative Network(带权并查集)

这个题的题意是  当输入'E'是查找操作,查找从后面这个数到他的父亲这边的值,'I'代表把后面的数作为前面数的父亲 然后他们两个的差值代表这两个边的权值 水水的题 #include <stdio.h> #include <string.h> int par[20005]; int rank1[20005]; int abs(int hh) { return (hh>0)?hh:-hh; } void init() { for(int i=0;i<20005;i++) {

ZOJ 2182 Cable TV Network(无向图点割-最大流)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2182 题意:给出一个无向图,问最少删掉多少个顶点之后图变得不连通? 思路:将原图每个点拆点(i,i+n),连边<i,i+n,1>,对原图的边(u,v),连边<u+n,v,INF>,<v+n,u,INF>.然后对于每对顶点(i,j)跑最大流(i+n,j).所有最大流的最小值即为答案. struct node { int v,cap,nex

【BZOJ】1146: [CTSC2008]网络管理Network(树链剖分+线段树套平衡树+二分 / dfs序+树状数组+主席树)

第一种做法(时间太感人): 这题我真的逗了,调了一下午,疯狂造数据,始终找不到错. 后来发现自己sb了,更新那里没有打id,直接套上u了.我.... 调了一下午啊!一下午的时光啊!本来说好中午A掉去学习第二种做法,噗 好吧,现在第一种做法是hld+seg+bst+二分,常数巨大,log^4级别,目前只会这种. 树剖后仍然用线段树维护dfs序区间,然后在每个区间建一颗平衡树,我用treap,(这题找最大啊,,,囧,并且要注意,这里的rank是比他大的数量,so,我们在二分时判断要判断一个范围,即要

poj459--Power Network(最大流EK、)

Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 23114   Accepted: 12103 Description A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied

ZOJ 1586 QS Network (经典MST~Prim)

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=586 In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunicate with each other via networks. If two QS want to get connected, they need to buy two n

poj 1459 Power Network (dinic)

Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 23059   Accepted: 12072 Description A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied

poj 2349 Arctic Network (prim算法)

Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10525   Accepted: 3470 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication tec

poj 1861 Network (kruskal)

Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13633   Accepted: 5288   Special Judge Description Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the c