传送门

题目大意

有两种染料,给定它们的单价和数量,每染色一米需耗费一个单位的染料,一条边只能用一种燃料,给你一张图,要求你将其中的一些边染色使得在满足图联通的情况下花费最小并输出方案。

分析

首先,要求图联通且花费最小我们不由想到了求最小生成树,在求完之后我们的问题就变成的看每条边要被染成哪种颜色。我们用dpij表示考虑了前i条边,第一种染料(5号染料)用的数量,并用数组记录一下在这种情况下所选的染料种类就可以了,详见代码。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
const int inf=0x3f3f3f3f;
struct node {
int x,y,z,id;
}d[];
int dp[][],pre[],p5,q5,p6,q6,n,m,wh[],fa[],cnt,tot;
bool ch[][];
struct ans {
int a,b;
}out[];
bool cmp(const node a,const node b){return a.z<b.z;}
bool cmp2(const ans a,const ans b){return a.a<b.a;}
inline int sf(int x){return fa[x]==x?x:fa[x]=sf(fa[x]);}
int main(){
freopen("domestic.in","r",stdin);
freopen("domestic.out","w",stdout);
int i,j,k;
scanf("%d%d",&n,&m);
for(i=;i<=m;i++){
scanf("%d%d%d",&d[i].x,&d[i].y,&d[i].z);
d[i].id=i;
}
scanf("%d%d%d%d",&p5,&q5,&p6,&q6);
sort(d+,d+m+,cmp);
for(i=;i<=n;i++)fa[i]=i;
for(i=;i<=m;i++){
if(sf(d[i].x)!=sf(d[i].y)){
fa[sf(d[i].x)]=sf(d[i].y);
cnt++;
pre[cnt]=pre[cnt-]+d[i].z;
wh[cnt]=i;
}
if(cnt==n-)break;
}
if(cnt<n-){
puts("Impossible");
return ;
}
memset(dp,0x3f,sizeof(dp));
dp[][]=;
for(i=;i<=cnt;i++)
for(j=;j<=min(q5,pre[i]);j++){
if(pre[i]-j>=d[wh[i]].z&&pre[i]-j<=q6)
dp[i][j]=dp[i-][j]+d[wh[i]].z*p6;
if(j>=d[wh[i]].z&&dp[i][j]>dp[i-][j-d[wh[i]].z]+d[wh[i]].z*p5){
dp[i][j]=dp[i-][j-d[wh[i]].z]+d[wh[i]].z*p5;
ch[i][j]=;
}
}
int ans=inf,pl;
for(i=;i<=q5;i++){
if(dp[cnt][i]<ans){
ans=dp[cnt][i];
pl=i;
}
}
if(ans==inf)puts("Impossible");
else {
cout<<ans<<endl;
for(i=cnt;i>;i--)
if(ch[i][pl]){
cout<<d[wh[i]].id<<' '<<<<endl;
pl-=d[wh[i]].z;
}else cout<<d[wh[i]].id<<' '<<<<endl;
}
return ;
}

100078D Domestic Networks的更多相关文章

  1. POJ - 3538 - Domestic Networks

    先上题目: Domestic Networks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 732   Accepted: ...

  2. ActiveMQ笔记(3):基于Networks of Brokers的HA方案

    上一篇介绍了基于ZK的ActiveMQ HA方案,虽然理解起来比较容易,但是有二个不足: 1)  占用的节点数过多,1个zk集群至少3个节点,1个activemq集群也至少得3个节点,但其实正常运行时 ...

  3. 【转】Artificial Neurons and Single-Layer Neural Networks

    原文:written by Sebastian Raschka on March 14, 2015 中文版译文:伯乐在线 - atmanic 翻译,toolate 校稿 This article of ...

  4. OpenFlow:Enabling Innovation in Campus Networks

    SDN领域,OpenFLow现在已经成为了广泛使用的南向接口协议.若想好好学习SDN,在这个领域有所进步,需要熟悉OpenFlow协议.我最近找了篇有关OpenFLow的论文,发现最早该协议是在Sig ...

  5. Spatial Transformer Networks(空间变换神经网络)

    Reference:Spatial Transformer Networks [Google.DeepMind]Reference:[Theano源码,基于Lasagne] 闲扯:大数据不如小数据 这 ...

  6. tensorfolw配置过程中遇到的一些问题及其解决过程的记录(配置SqueezeDet: Unified, Small, Low Power Fully Convolutional Neural Networks for Real-Time Object Detection for Autonomous Driving)

    今天看到一篇关于检测的论文<SqueezeDet: Unified, Small, Low Power Fully Convolutional Neural Networks for Real- ...

  7. 论文阅读(Xiang Bai——【CVPR2016】Multi-Oriented Text Detection with Fully Convolutional Networks)

    Xiang Bai--[CVPR2016]Multi-Oriented Text Detection with Fully Convolutional Networks 目录 作者和相关链接 方法概括 ...

  8. VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE-SCALE IMAGE RECOGNITION 这篇论文

    由Andrew Zisserman 教授主导的 VGG 的 ILSVRC 的大赛中的卷积神经网络取得了很好的成绩,这篇文章详细说明了网络相关事宜. 文章主要干了点什么事呢?它就是在在用卷积神经网络下, ...

  9. Deep Learning 26:读论文“Maxout Networks”——ICML 2013

    论文Maxout Networks实际上非常简单,只是发现一种新的激活函数(叫maxout)而已,跟relu有点类似,relu使用的max(x,0)是对每个通道的特征图的每一个单元执行的与0比较最大化 ...

随机推荐

  1. GUID在.net里的使用

    GUID(全局统一标识符)是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成GUID的API.生成算法很有意思,用到了以太网卡地址.纳秒级时间.芯片ID码和许多可 ...

  2. hdoj-3342-Legal or Not(拓扑排序)

    题目链接 /* Name:hdoj-3342-Legal or Not Copyright: Author: Date: 2018/4/11 15:59:18 Description: 判断是否存在环 ...

  3. 自定义php(NON-CORE WORDPRESS FILE) 引用 wordpress

    在文件头头添加下面代码,实现此页面可以调用wordpress的内置方法 <?php $parse_uri = explode ( 'wp-content', $_SERVER ['SCRIPT_ ...

  4. Apache POI实现excel导出

    链接:http://poi.apache.org/ Excel数据导出步骤: 使用poi 完成账户数据的导出功能 导入poi  jar包并添加到classpath中 1.查询数据 2.定义导出头 St ...

  5. 如何用nodejs启一个前端服务

    1.新建文件夹,如 notice 2.新建页面和js文件,如 index.html server.js 3.index.html页面内容随你写,如: <!DOCTYPE html> < ...

  6. 学习动态性能表(18)--v$system_event

    学习动态性能表 第18篇--V$SYSTEM_EVENT  2007.6.13 本视图概括了实例各项事件的等待信息.v$session_wait显示了系统的当前等待项,v$system_event则提 ...

  7. poj 2096 , zoj 3329 , hdu 4035 —— 期望DP

    题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...

  8. 12.Selenium+Python案例 -- 今日头条(获取科技栏目的所有新闻标题)

    一:具体代码实现 # -*- coding: utf-8 -*-# @Time : 2018/7/26 16:33# @Author : Nancy# @Email : NancyWangDL@163 ...

  9. LeetCode第五题:Longest Palindromic Substring

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  10. MSSQL Join的使用

    假设我们有下面两张表.表A在左边,表B在右边.我们给它们各四条记录. id name id name -- ---- -- ---- 1 Pirate 1 Rutabaga 2 Monkey 2 Pi ...