Network Wars

Time Limit: 5000ms
Memory Limit: 32768KB

This problem will be judged on ZJU. Original ID: 2676
64-bit integer IO format: %lld      Java class name: Main

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

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 5
1 2 2
1 3 2
2 3 1
2 4 2
3 4 2 Output
4
3 4 5 6
3
1 2 3

Source

解题:最大流-分数规划?不懂。。。好厉害的样子啊
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
const double exps = 1e-;
struct arc{
int to,next,id;
double flow;
arc(int x = ,double y = ,int z = ,int nxt = -){
to = x;
flow = y;
id = z;
next = nxt;
}
};
arc e[];
int head[maxn],d[maxn],cur[maxn],xx[maxn<<],yy[maxn<<];
int tot,S,T,n,m;
double ww[maxn<<];
bool used[maxn<<],vis[maxn<<];
void add(int u,int v,double flow,int id){
e[tot] = arc(v,flow,id,head[u]);
head[u] = tot++;
e[tot] = arc(u,,id,head[v]);
head[v] = tot++;
}
bool bfs(){
queue<int>q;
memset(d,-,sizeof(d));
d[S] = ;
q.push(S);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].flow > exps && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
double dfs(int u,double low){
if(u == T) return low;
double tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow > exps && d[e[i].to] == d[u] + && (a = dfs(e[i].to,min(low,e[i].flow))) > exps){
e[i].flow -= a;
e[i^].flow += a;
tmp += a;
low -= a;
if(low < exps) break;
}
}
if(tmp < exps) d[u] = -;
return tmp;
}
double dinic(){
double tmp = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
tmp += dfs(S,INF);
}
return tmp;
}
double init(double delta){
double tmp = tot = ;
memset(head,-,sizeof(head));
memset(used,false,sizeof(used));
for(int i = ; i <= m; ++i){
if(ww[i] - delta <= exps){
used[i] = true;
tmp += ww[i] - delta;
}else{
add(xx[i],yy[i],ww[i]-delta,i);
add(yy[i],xx[i],ww[i]-delta,i);
}
}
return tmp;
}
void dfs2(int u){
vis[u] = true;
for(int i = head[u]; ~i; i = e[i].next)
if(e[i].flow > exps && !vis[e[i].to]) dfs2(e[i].to);
}
int main(){
bool flag = false;
while(~scanf("%d %d",&n,&m)){
S = ;
T = n;
if(flag) puts("");
flag = true;
for(int i = ; i <= m; ++i) scanf("%d %d %lf",xx+i,yy+i,ww+i);
double mid,low = ,high = INF,ans = ;
while(fabs(high - low) > 1e-){
mid = (low + high)/2.0;
ans = init(mid);
ans += dinic();
if(ans > ) low = mid;
else high = mid;
}
memset(vis,false,sizeof(vis));
dfs2(S);
vector<int>res;
for(int i = ; i < n; ++i)
for(int j = head[i]; ~j; j = e[j].next)
if(vis[i] != vis[e[j].to]) used[e[j].id] = true;
for(int i = ; i <= m; ++i)
if(used[i]) res.push_back(i);
printf("%d\n",res.size());
for(int i = ; i < res.size(); ++i)
printf("%d%c",res[i],i == res.size()-?'\n':' ');
}
return ;
}

ZJU 2676 Network Wars的更多相关文章

  1. ZOJ 2676 Network Wars[01分数规划]

    ZOJ Problem Set - 2676 Network Wars Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special J ...

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

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

  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. ZOJ 2676 Network Wars ★(最小割算法介绍 && 01分数规划)

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

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

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

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

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

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

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

  8. Network Wars

    zoj2676:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1676 题意:给出一个带权无向图 ,每条边e有一个权 .求将点 ...

  9. zju2676 Network Wars 分数规划+网络流

    题意:给定无向图,每条边有权值,求该图的一个割集,是的该割集的平均边权最小 Amber的<最小割模型在信息学竞赛中的应用>中讲的很清楚了. 二分答案k,对每条边进行重新赋值为原边权-k,求 ...

随机推荐

  1. 公司组织oracle培训的理解

    oracle执行机制 1.客户端发送一条sql给oracle服务器,oracle会看这条sql的执行计划是否存在缓存  如果存在则直接运行,如果不存在执行第二步. 2.如果不存在缓存 则会 进行语法检 ...

  2. 模拟ArrayList底层实现

    package chengbaoDemo; import java.util.ArrayList; import java.util.Arrays; import comman.Human; /** ...

  3. GA求解TSP

    遗传算法中包含了如下5个基本要素: (1)对参数进行编码: (2)设定初始种群大小: (3)适应度函数的设计: (4)遗传操作设计: (5)控制参数设定(包括种群大小.最大进化代数.交叉率.变异率等) ...

  4. Unity里包裹Debug,且不影响Debug的重定向

    Debug.Log, Debug.LogWarning, Debug.LogError在project中常常须要再包裹一层.做些定制.也方便开关Log.但有一个问题时.当用一个类将Debug包裹起来后 ...

  5. jQuery验证所有输入合法后才干提交

    大学三年里所有在专注后台编码.学会不知多少种,servlet.ssh,springMVC,web.py...... 最后每次碰到前端自己要写点东西就满目愁抑, 干脆自己好好理解一段前端代码, 特地拿出 ...

  6. Java线程池原理与架构分析

    /** * 一.线程池:提供了一个线程队列,队列中保存着所有等待状态的线程.避免了创建与销毁额外开销,提高了响应速度 * 二.线程池的体系结构 * java.util.concurrent.Execu ...

  7. 如何用写js弹出层 ----2017-03-29

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. Ubuntu14.04下Mongodb数据库可视化工具安装部署步骤(图文详解)(博主推荐)

    不多说,直接上干货! 前期博客 Ubuntu14.04下Mongodb(离线安装方式|非apt-get)安装部署步骤(图文详解)(博主推荐) Ubuntu14.04下Mongodb官网安装部署步骤(图 ...

  9. Oracle学习系类篇(三)

    1. 存储过程 CREATE  OR REPLACE PROCEDURE  SP_NAME( PM_NAME [IN/OUT/IN OUT] PM_TYPE...)            {AS}   ...

  10. 高并发之web服务器负载均衡简单介绍

    负载均衡种类 F5,七层负载均衡,四层负载均衡 Nginx负载均衡 内置策略.扩展策略 内置策略:IPHash.加权轮询 扩展策略:fair策略.通用hash.一致性hash 加权轮询策略 首先将请求 ...