Battle over Cities

 

Battle over Cities

Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 4   Accepted Submission(s) : 0
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

It is vitally important to have all the cities connected by highways in a war, but some of them are destroyed now because of the war. Furthermore,if a city is conquered, all the highways from/toward that city will be closed by the enemy, and we must repair some destroyed highways to keep other cities connected, with the minimum cost if possible.
Given the map of cities which have all the destroyed and remaining highways marked, you are supposed to tell the cost to connect other cities if each city is conquered by the enemy.

Input

The input contains multiple test cases. The first line is the total number of cases T (T ≤ 10). Each case starts with a line containing 2 numbers N (0 < N ≤ 20000), and M (0 ≤ M ≤ 100000), which are the total number of cities, and the number of highways, respectively. Then M lines follow, each describes a highway by 4 integers: City1 City2 Cost Status where City1 and City2 are the numbers of the cities the highway connects (the cities are numbered from 1 to N), Cost (0 < Cost ≤ 20000) is the effort taken to repair that highway if necessary, and Status is either 0, meaning that highway is destroyed, or 1, meaning that highway is in use.
Note: It is guaranteed that the whole country was connected before the war and there is no duplicated high ways between any two cities.

Output

For each test case, output N lines of integers. The integer in the i-th line indicates the cost to keep the cities connected if the i-th city is conquered by the enemy. In case the cities cannot be connected after the i-th city is conquered by the enemy, output "inf" instead in the corresponding place.

Sample Input

3
4 5
1 2 1 1
1 3 1 1
2 3 1 0
2 4 1 1
3 4 2 0
4 5
1 2 1 1
1 3 1 1
2 3 1 0
2 4 1 1
3 4 1 0
3 2
1 2 1 1
1 3 1 1

Sample Output

1
2
0
0
1
1
0
0
inf
0
0

Author

GUAN, Yao

Source

The 2010 ACM-ICPC Asia Chengdu Regional Contest
 
错误的代码:供自己以后修改
听说这道题要用割点+最小生成树

#include<iostream>
#include<stdio.h>
#include<algorithm>
#define MAXN 20001
using namespace std;
int city,load;
int i,j;
struct edge
{
 int u;
 int v;
 int cost;
 int destory;
}edges[MAXN];
int parent[MAXN];

void UFset()
{
 for(j=1;j<=city;j++)
 {
  parent[j]=-1;
 }
}

int Find(int x)
{
 int s;
 for(s=x;parent[s]>=0;s=parent[s]);
 while(s!=x)
 {
  int tmp=parent[x];
  parent[x]=s;
  x=tmp;
 }
 return s;
}

void Union(int R1,int R2)
{
int r1=Find(R1);
int r2=Find(R2);
int tmp=parent[r1]+parent[r2];
if(parent[r1]>parent[r2])
{
 parent[r1]=r2;
 parent[r2]=tmp;
}
else
{
 parent[r2]=r1;
 parent[r1]=tmp;
}
}

int cmp(const void*a,const void*b)
{
 edge aa=*(const edge*)a;
 edge bb=*(const edge*)b;
 return aa.cost-bb.cost;
}

void Kruskal(int t)
{
 int sumweight=0;
 int num=0;
 int u,v;
 UFset();
 for(j=0;j<load;j++)
 {
  u=edges[j].u;
  v=edges[j].v;
  if(u==t || v==t)
   continue;
  if(Find(u)!=Find(v))
  {
   sumweight+=edges[j].cost;
   num++;
   Union(u,v);
  }
 // if(num>=city-1)
  // break;
 }
 if(num==city-2)
 printf("%d\n",sumweight);
 else
  printf("inf\n");
}

int main()
{
 int n;
 int u,v,cost,destory;
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  scanf("%d%d",&city,&load);
  for(j=0;j<load;j++)
  {
   scanf("%d%d%d%d",&u,&v,&cost,&destory);
   edges[j].u=u;
   edges[j].v=v;
   if(destory==1)
   edges[j].cost=0;
   else
    edges[j].cost=cost;
  }
  qsort(edges,load,sizeof(edges[0]),cmp);
  int t;
  for(t=1;t<=city;t++)
  {
  Kruskal(t);
  }
 }
 return 0;
}

内容概要:FS70系列显微镜是一款高功率、符合人体工程学设计的半导体检测显微镜。该系列显微镜采用Mitutoyo无限远校正光学系统和Siedentopf设计的三目镜筒,配备10倍广角目镜(视场数为24),提供四种主要机型:标准型、带变焦功能的非激光型、适用于三种YAG激光波长的型号以及适用于两种波长范围的型号。其物镜放大倍率从1倍到200倍不等,支持长工作距离平场消色差物镜、激光切割物镜以及红外、近红外、紫外和近紫外应用的长工作距离物镜。此外,还提供了微分干涉对比选项(仅限非激光配置)、可选的电动四孔中心调节目镜以及六英尺遥控光强控制。所有型号均具有同心粗调和微调聚焦轮,提供50毫米行程范围,微调精度达0.1毫米/转。 适合人群:从事半导体行业及相关领域的技术人员、研究人员和质量控制人员。 使用场景及目标:①用于半导体晶圆、芯片和其他微小元件的高精度检测;②适用于科研实验室进行材料微观结构分析;③支持工业生产中的产品质量检验与故障排查。 阅读建议:本资料详细介绍了FS70系列显微镜的技术参数和特点,建议使用者根据具体应用场景选择合适的配置,并参考提供的配件选项来优化观测效果。同时,在操作过程中应注意安全事项,特别是涉及激光应用时需遵循相关法规要求。
【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍,个人大四的毕业设计、经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。 【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+数据集+项目介绍【Python毕业设计】-基于卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计源码+
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值