ZOJ Problem Set - 2676
Network Wars

Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge

Network of Byteland consists of n servers, connected by m optical cables. Each cable connects two servers and can transmit data in both directions. Two servers of the network are especially important --- they are connected to global world network and president palace network respectively.

The server connected to the president palace network has number 1, and the server connected to the global world network has number n.

Recently the company Max Traffic has decided to take control over some cables so that it could see what data is transmitted by the president palace users. Of course they want to control such set of cables, that it is impossible to download any data from the global network to the president palace without transmitting it over at least one of the cables from the set.

To put its plans into practice the company needs to buy corresponding cables from their current owners. Each cable has some cost. Since the company's main business is not spying, but providing internet connection to home users, its management wants to make the operation a good investment. So it wants to buy such a set of cables, that cables mean cost} is minimal possible.

That is, if the company buys k cables of the total cost c, it wants to minimize the value of c/k.

Input

There are several test cases in the input. The first line of each case contains n and m (2 <= n <= 100 , 1 <= m <= 400 ). Next m lines describe cables~--- each cable is described with three integer numbers: servers it connects and the cost of the cable. Cost of each cable is positive and does not exceed 107.

Any two servers are connected by at most one cable. No cable connects a server to itself. The network is guaranteed to be connected, it is possible to transmit data from any server to any other one.

There is an empty line between each cases.

Output

First output k --- the number of cables to buy. After that output the cables to buy themselves. Cables are numbered starting from one in order they are given in the input file. There should an empty line between each cases.

Example

Input Output
6 8 1 2 3 1 3 3 2 4 2 2 5 2 3 4 2 3 5 2 5 6 3 4 6 3 
4 3 4 5 6  
4 5 1 2 2 1 3 2 2 3 1 2 4 2 3 4 2 
3 1 2 3 

Source: Andrew Stankevich's Contest #8
Submit    Status  

include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef double real;
const real eps=1e-;
const int Z=1e3+,N=1e4+,M=1e5+;
struct data{int u,v,w;}a[Z];
struct edge{int v,next;real cap;}e[M];int tot=,head[N];
int n,m,S,T,cas,num,g[Z],dis[N],q[M];bool vis[Z];
real L,R,ans;
inline int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline int dcmp(real x){
if(fabs(x)<eps) return ;
return x>?:-;
}
inline void add(int x,int y,real z){
e[++tot].v=y;e[tot].cap=z;e[tot].next=head[x];head[x]=tot;
e[++tot].v=x;e[tot].cap=z;e[tot].next=head[y];head[y]=tot;
}
inline bool bfs(){
for(int i=S;i<=T;i++) dis[i]=-;
int h=,t=;q[t]=S;dis[S]=;
while(h!=t){
int x=q[++h];
for(int i=head[x];i;i=e[i].next){
if(dcmp(e[i].cap)>&&dis[e[i].v]==-){
dis[e[i].v]=dis[x]+;
if(e[i].v==T) return ;
q[++t]=e[i].v;
}
}
}
return ;
}
real dfs(int x,real f){
if(x==T) return f;
real used=,t;
for(int i=head[x];i;i=e[i].next){
if(dcmp(e[i].cap)>&&dis[e[i].v]==dis[x]+){
t=dfs(e[i].v,min(e[i].cap,f));
e[i].cap-=t;e[i^].cap+=t;
used+=t;f-=t;
if(!f) return used;
}
}
if(!used) dis[x]=-;
return used;
}
inline real dinic(){
real res=;
while(bfs()) res+=dfs(S,2e9);
return res;
}
inline void init(){
m=read();L=;R=;num=;S=;T=n;
for(int i=;i<=m;i++) a[i].u=read(),a[i].v=read(),a[i].w=read(),R+=a[i].w;
}
inline real rebuild(real s){
tot=;memset(head,,n+<<);
real tans=;
for(int i=;i<=m;i++){
if(a[i].w>s){
add(a[i].u,a[i].v,a[i].w-s);
}
else tans+=a[i].w-s;
}
return tans+dinic();
}
inline real binary_search(){
real mid,now;
while(dcmp(R-L)>){
mid=(L+R)/;
now=rebuild(mid);
if(dcmp(now)>) L=mid;
else R=mid;
}
return mid;
}
void DFS(int x){
vis[x]=;
for(int i=head[x];i;i=e[i].next){
if(!vis[e[i].v]&&dcmp(e[i].cap)>){
DFS(e[i].v);
}
}
}
inline void work(){
ans=binary_search();
memset(vis,,n+<<);
//rebuild(ans);
DFS(S);
for(int i=;i<=m;i++){
if(vis[a[i].u]+vis[a[i].v]==||a[i].w<ans){
g[++num]=i;
}
}
if(cas++) putchar('\n');
printf("%d\n",num);
for(int i=;i<num;i++) printf("%d ",g[i]);
if(num) printf("%d",g[num]);
putchar('\n');
}
int main(){
while(~scanf("%d",&n)) init(),work();
return ;
}

ZOJ 2676 Network Wars[01分数规划]的更多相关文章

  1. zoj 2676 Network Wars 0-1分数规划+最小割

    题目详解出自 论文 Amber-最小割模型在信息学竞赛中的应用 题目大意: 给出一个带权无向图 G = (V,E), 每条边 e属于E都有一个权值We,求一个割边集C,使得该割边集的平均边权最小,即最 ...

  2. ZOJ 2676 Network Wars(网络流+分数规划)

    传送门 题意:求无向图割集中平均边权最小的集合. 论文<最小割模型在信息学竞赛中的应用>原题. 分数规划.每一条边取上的代价为1. #include <bits/stdc++.h&g ...

  3. HDU 2676 Network Wars 01分数规划,最小割 难度:4

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1676 对顶点i,j,起点s=1,终点t=n,可以认为题意要求一组01矩阵use ...

  4. zoj2676 Network Wars(0-1分数规划,最大流模板)

    Network Wars 07年胡伯涛的论文上的题:http://wenku.baidu.com/view/87ecda38376baf1ffc4fad25.html 代码: #include < ...

  5. ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)

    [题意]给出一个带权无向图,求割集,且割集的平均边权最小. [分析] 先尝试着用更一般的形式重新叙述本问题.设向量w表示边的权值,令向量c=(1, 1, 1, --, 1)表示选边的代价,于是原问题等 ...

  6. ZOJ 2676 Network Wars(最优比例最小割)

    Network Wars Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge Network of Bytelan ...

  7. ZOJ - 2676 01分数规划 浮点ISAP

    题意:求最小割集\(C\),使得\(\frac{\sum_{i∈C} cost_i}{|C|}\)最小 模型就是01分数规划\(\frac{\sum_{i=1}^{m}cost_i*x}{\sum_{ ...

  8. zoj 2676 二分+ISAP模板求实型参数的最小割(0-1分数规划问题)(可做ISAP模板)

    /* 参考博文:http://www.cnblogs.com/ylfdrib/archive/2010/09/01/1814478.html 以下题解为转载代码自己写的: zoj2676 胡伯涛论文& ...

  9. 【转】[Algorithm]01分数规划

    因为搜索关于CFRound277.5E题的题解时发现了这篇文章,很多地方都有值得借鉴的东西,因此转了过来 原文:http://www.cnblogs.com/perseawe/archive/2012 ...

随机推荐

  1. 后台dubug有值且sql也打印出来执行了但是前台就是查不到数据

    记录在sturts2里面 摔得最深的一次 public String queryJoinAccount(){ //用来存储分页的数据 pageMap=new HashMap<String, Ob ...

  2. javascript中call apply的区别

    obj.call(thisObj, arg1, arg2, ...); obj.apply(thisObj, [arg1, arg2, ...]); 两者作用一致,都是把obj(即this)绑定到th ...

  3. SQLyog之MySQL客户端的下载、安装和使用(普通版)

    本博文的主要内容有 .SQLyog的下载 .SQLyog的安装 .SQLyog的使用 前期,安装这个,不多说 MySQL Server类型之MySQL客户端工具的下载.安装和使用 1.SQLyog的下 ...

  4. 删除Git记录里的大文件

    删除Git记录里的大文件 仓库自身的增长 大多数版本控制系统存储的是一组初始文件,以及每个文件随着时间的演进而逐步积累起来的差异:而 Git 则会把文件的每一个差异化版本都记录在案.这意味着,即使你只 ...

  5. atom搭建markdown环境及问题

    1. 搭建markdown环境 > 禁用atom自带的markdown-preview插件(功能简单) > 安装插件:markdown-preview-plus@2.4.16(在markd ...

  6. C++程序设计项目开发——银行自己主动提款机(二)

    函数的有关知识在后面章节会讲到,先提前了解下.在没有系统的学习完之前,咱们先来模仿着写一个样例,尝试这样的有效的学习方法.   尝试下这种学习方法. 显示功能选项 1.查询 2.取款 3.存款 4.转 ...

  7. MooseFS管理

    一.goal(副本) 副本,在MFS中也被称为目标(Goal),它是指文件被复制的份数,设定目标值后可以通过mfsgetgoal命令来证实,也可以通过mfssetgoal命令来改变设定. 1 2 3 ...

  8. python学习之endswith()

    定义: Python endswith() 方法用于判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False.可选参数"start"与"end&q ...

  9. layui基础上的tree菜单动态渲染;

    var layout=[ { title:'脚本对象名称', treeNodes:true, headerClass:'value_col', colClass:'value_col', style: ...

  10. CCNA2.0笔记_IPv6

    IPv6地址表示方法: 连续的零字段可表示为:: (每个地址只能用一次) 示例: 2031:0000:130F:0000:0000:09C0:876A:130B –可表示为2031:0:130f::9 ...