HDU 2121 Ice_cream’s world II (最小树形图+虚点,4级)

在冰激凌世界中,女王授予土地给ACM者,并要求选择一个合适的地点作为首都。这个世界有N个城市和M条道路,每条道路都是有向的。Wiskey作为首席工程师,需要找到一个位置建立首都,使得从该位置出发可以访问每个城市,同时确保项目成本尽可能低。如果无法满足女王的要求,则输出“impossible”。反之,则输出最小成本和合适的城市编号。
C - Ice_cream’s world II
Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

After awarded lands to ACMers, the queen want to choose a city be her capital. This is an important event in ice_cream world, and it also a very difficult problem, because the world have N cities and M roads, every road was directed. Wiskey is a chief engineer in ice_cream world. The queen asked Wiskey must find a suitable location to establish the capital, beautify the roads which let capital can visit each city and the project’s cost as less as better. If Wiskey can’t fulfill the queen’s require, he will be punishing.
 

Input

Every case have two integers N and M (N<=1000, M<=10000), the cities numbered 0…N-1, following M lines, each line contain three integers S, T and C, meaning from S to T have a road will cost C.
 

Output

If no location satisfy the queen’s require, you must be output “impossible”, otherwise, print the minimum cost in this project and suitable city’s number. May be exist many suitable cities, choose the minimum number city. After every case print one blank.
 

Sample Input

     
3 1 0 1 1 4 4 0 1 10 0 2 10 1 3 20 2 3 30
 

Sample Output

     
impossible 40 0
思路:建一个虚节点,向其他所有点连边值比其他所有边和大,为sum,最后一定会得到最小树形图,判断这个最小树形图的值比sum+sum大则说明选了两条这种边,无答案
否则答案就是其减去sum,边就是选了root 的边,由此可知道树根
#include<cstdio>
#include<cstring>
#include<iostream>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define clr(f,z) memset(f,z,sizeof(f))
typedef long long type;
using namespace std;
const int nn=1005;
const int mm=17009;
const long long oo=1e18;
type sum;
class Edge
{
  public:int u,v;type w;
}e[mm];
int id[nn],vis[nn],pre[mm],city;
type in[nn];
type Directed_MST(int root,int V,int E)
{
  type ret=0;
  while(1)
  {
    FOR(i,0,V-1)in[i]=oo;
    in[root]=0;
    int u,v;
    FOR(i,0,E-1)
    {
      u=e[i].u;v=e[i].v;
      if(u!=v&&e[i].w<in[v])
      {
        in[v]=e[i].w;pre[v]=u;
        if(u==root)
          city=i;
      }
    }
    FOR(i,0,V-1)
    if(in[i]==oo)return -1;
    //find cicle
    int bcc_no=0;
    clr(vis,-1);clr(id,-1);
    FOR(i,0,V-1)
    { ret+=in[i];//if(in[i]==sum)city=i;
      v=i;
      while(vis[v]!=i&&id[v]==-1&&v!=root)
        vis[v]=i,v=pre[v];
      if(v!=root&&id[v]==-1)
      {
        for(int u=pre[v];u!=v;u=pre[u])
          id[u]=bcc_no;
        id[v]=bcc_no++;
      }
    }
    if(bcc_no==0)break;
    FOR(i,0,V-1)
    if(id[i]==-1)
      id[i]=bcc_no++;
    FOR(i,0,E-1)
    {
      u=e[i].u;v=e[i].v;
      e[i].u=id[u];
      e[i].v=id[v];
      if(id[u]^id[v])e[i].w-=in[v];
    }
    V=bcc_no;root=id[root];
  }
  return ret;
}
int main()
{ int n,m;
  while(~scanf("%d%d",&n,&m))
  { sum=0;
    FOR(i,0,m-1)
    {
      scanf("%d%d%I64d",&e[i].u,&e[i].v,&e[i].w);
      sum+=e[i].w;
    }
    ++sum;
    FOR(i,0,n-1)
    e[i+m].u=n,e[i+m].v=i,e[i+m].w=sum;
    type ans=Directed_MST(n,n+1,n+m);
    //cout<<ans<<endl;
    ans-=sum;
    if(ans>=sum)printf("impossible\n");
    else printf("%I64d %d\n",ans,city-m);
    printf("\n");
  }
  return 0;
}


考虑柔性负荷的综合能源系统低碳经济优化调度【考虑碳交易机制】(Matlab代码实现)内容概要:本文围绕“考虑柔性负荷的综合能源系统低碳经济优化调度”展开,重点研究在碳交易机制下如何实现综合能源系统的低碳化与经济性协同优化。通过构建包含风电、光伏、储能、柔性负荷等多种能源形式的系统模型,结合碳交易成本与能源调度成本,提出优化调度策略,以降低碳排放并提升系统运行经济性。文中采用Matlab进行仿真代码实现,验证了所提模型在平衡能源供需、平抑可再生能源波动、引导柔性负荷参与调度等方面的有效性,为低碳能源系统的设计与运行提供了技术支撑。; 适合人群:具备一定电力系统、能源系统背景,熟悉Matlab编程,从事能源优化、低碳调度、综合能源系统等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究碳交易机制对综合能源系统调度决策的影响;②实现柔性负荷在削峰填谷、促进可再生能源消纳中的作用;③掌握基于Matlab的能源系统建模与优化求解方法;④为实际综合能源项目提供低碳经济调度方案参考。; 阅读建议:建议读者结合Matlab代码深入理解模型构建与求解过程,重点关注目标函数设计、约束条件设置及碳交易成本的量化方式,可进一步扩展至多能互补、需求响应等场景进行二次开发与仿真验证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值