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. Elasticsearch 7.0 正式发布,盘他!

    Elastic{ON}北京分享了Elasticsearch7.0在Speed,Scale,Relevance等方面的很多新特性. 比快更快,有传说中的那么牛逼吗?盘他! 通过本文,你能了解到: Ela ...

  2. BA-siemens-desigo_cc安装

    1.首先安装NT3.5和NT4.0软件 2.按照以下网址的教程配置好IIS和WEBDAV环境:http://www.cnblogs.com/xiongzai/p/4126493.html 文章写的真不 ...

  3. leetCode 66.Plus One (+1问题) 解题思路和方法

    Plus One Given a non-negative number represented as an array of digits, plus one to the number. The ...

  4. cmd 进入mysql 小技巧

    1.開始中找出执行:输入cmd 2.查找appserv所在盘,我的在D盘.所以接着输入:d: 3.在d盘中查找mysql所在文件夹:cd appserv\mysql\bin 4.再输入主机名.数据库名 ...

  5. 2015.05.18,外语,学习笔记-《Word Power Made Easy》 03 “如何谈论不同从业者”

    Prefix Person,nous,etc. Practice,etc. Adjective psyche 精神 psychic ['saikik] adj.精神的n.灵媒 -logos 科研 ps ...

  6. 2015.04.29,外语,读书笔记-《Word Power Made Easy》 14 “如何谈论日常现象” SESSION 39

    HOW TO TALK ABOUT COMMON PHENOMENA AND OCCURRENCES TEASER PREVIEW dire(['daiә(r)] adj. 可怕的,悲惨的,灾难警告的 ...

  7. Java中Array、List、Set、Map

    一.Java中数组 数组用来存放固定数量的同类元素,声明方法: T[] ref,T ref[],如int[] intAry; int intAry[].推荐用T[]的方式,后一种方式为兼容C++习惯写 ...

  8. electron-vue中使用iview 报错this. is readonly的解决办法

    title: electron-vue中使用iview 报错this. is readonly的解决办法 toc: false date: 2019-02-12 19:33:28 categories ...

  9. SQL语句之WITH AS

    一.WITH AS的含义 WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到. 其实就是把一大堆 ...

  10. kettle的下载、安装和初步使用(Ubuntu 16.04平台下)(图文详解)

    不多说,直接上干货! 能够看我这篇博客的博友们,想必是已经具备一定基础了. 扩展博客 kettle的下载.安装和初步使用(windows平台下)(图文详解) kettle的下载 žKettle可以在h ...