HDU 6041.I Curse Myself 无向仙人掌图
I Curse Myself
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2266 Accepted Submission(s): 544
Assuming that the weight of a weighted spanning tree is the sum of weights on its edges, define V(k) as the weight of the k-th smallest weighted spanning tree of this graph, however, V(k) would be defined as zero if there did not exist k different weighted spanning trees.
Please calculate (∑k=1Kk⋅V(k))mod232.
For each test case, the first line contains two positive integers n,m (2≤n≤1000,n−1≤m≤2n−3), the number of nodes and the number of edges of this graph.
Each of the next m lines contains three positive integers x,y,z (1≤x,y≤n,1≤z≤106), meaning an edge weighted z between node x and node y. There does not exist multi-edge or self-loop in this graph.
The last line contains a positive integer K (1≤K≤105).
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define PI acos(-1.0)
#define eps 1e-8
typedef long long ll;
typedef pair<int,int> P;
const int N=1e3+,M=4e3+;
struct edge
{
int from,to;
int w;
int next;
};
int n,m,k;
edge es[M];
int cnt,head[N];
int dfs_clock=;
int pre[N],low[N];
stack<int>s;
void init(int n)
{
cnt=;
dfs_clock=;
for(int i=; i<=n+; i++) head[i]=-,pre[i]=;
}
void addedge(int u,int v,int w)
{
cnt++;
es[cnt].from=u,es[cnt].to=v;
es[cnt].w=w;
es[cnt].next=head[u];
head[u]=cnt;
}
int tmp[],ans[];
struct node
{
int num;
int id;
bool operator <(const node x) const
{
return x.num>num;
}
};
void unit(priority_queue<node> &q)
{
tmp[]=;
while(tmp[]<k&&!q.empty())
{
node x=q.top();
q.pop();
tmp[++tmp[]]=x.num;
if(++x.id<=ans[]) q.push((node)
{
x.num-ans[x.id-]+ans[x.id],x.id
});
}
ans[]=;
for(int i=; i<=tmp[]; i++) ans[++ans[]]=tmp[i];
}
bool dfs(int u,int fa)
{
pre[u]=low[u]=++dfs_clock;
for(int i=head[u]; i!=-; i=es[i].next)
{
int v=es[i].to;
if(v==fa) continue;
if(!pre[v])
{
s.push(i);
dfs(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=pre[u])
{
priority_queue<node>q;
while(!s.empty())
{
int poi=s.top();
s.pop();
q.push((node){ans[]+es[poi].w,});
if(poi==i) break;
}
if(q.size()>) unit(q);
}
}
else if(pre[v]<pre[u]&&v!=fa)
{
s.push(i);
low[u]=min(low[u],pre[v]);
}
}
}
int main()
{
int Case=;
while(scanf("%d%d",&n,&m)!=EOF)
{
init(n);
int all=;
for(int i=; i<=m; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
all+=w;
addedge(u,v,w),addedge(v,u,w);
}
scanf("%d",&k);
ans[]=,ans[++ans[]]=;
dfs(,);
ll sum=,mod=(1LL<<);
for(int i=; i<=ans[]; i++)
sum=(sum+(1LL*(all-ans[i])*i)%mod)%mod;
printf("Case #%d: %lld\n",++Case,sum);
}
return ;
}
无向仙人掌图
HDU 6041.I Curse Myself 无向仙人掌图的更多相关文章
- HDU 6041 - I Curse Myself | 2017 Multi-University Training Contest 1
和题解大致相同的思路 /* HDU 6041 - I Curse Myself [ 图论,找环,最大k和 ] | 2017 Multi-University Training Contest 1 题意 ...
- HDU 6041 I Curse Myself ——(仙人掌图,tarjan,转化)
题解见这个博客:http://blog.csdn.net/ME495/article/details/76165039. 复杂度不太会算..这个经典问题的解法需要注意,维护队列里面只有k个元素即可.另 ...
- HDU 6041 I Curse Myself(二分+搜索)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6041 [题目大意] 给出一个仙人掌图,求第k小生成树 [题解] 首先找到仙人掌图上的环,现在的问题 ...
- HDU 6041 I Curse Myself(点双联通加集合合并求前K大) 2017多校第一场
题意: 给出一个仙人掌图,然后求他的前K小生成树. 思路: 先给出官方题解 由于图是一个仙人掌,所以显然对于图上的每一个环都需要从环上取出一条边删掉.所以问题就变为有 M 个集合,每个集合里面都有一堆 ...
- hdu 6041 I Curse Myself
题目: 点这里OvO http://acm.hdu.edu.cn/showproblem.php?pid=6041 2017 Multi-University Training Contest - T ...
- hdu 6041 I Curse Myself 无向图找环+优先队列
I Curse Myself Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 3594.Cactus 仙人掌图
Cactus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 3594 Cactus /uva 10510 仙人掌图判定
仙人掌图(有向):同时满足:1强连通:2任何边不在俩个环中. 个人理解:其实就是环之间相连,两两只有一个公共点,(其实可以缩块),那个公共点是割点.HDU数据弱,网上很多错误代码和解法也可以过. 个人 ...
- HDU 3594 Cactus (强连通+仙人掌图)
<题目链接> <转载于 >>> > 题目大意: 给你一个图,让你判断他是不是仙人掌图. 仙人掌图的条件是: 1.是强连通图. 2.每条边在仙人掌图中只属于一个 ...
随机推荐
- Docker笔记——Docker安装及制作镜像
1 Docker安装本文中Docker运行环境为Ubuntu 14.04.1 LTS 3.13.0-32-generic x64参考:https://docs.docker.com/v1.11/eng ...
- Btrace官方教程-中文版
教程英文版来源:https://github.com/btraceio/btrace/blob/master/docs/usersguide.html BTrace用户指南 BTrace是一种安全,动 ...
- azkaban工作流调度器及相关工具对比
本文转载自:工作流调度器azkaban,主要用于架构选型,安装请参考:Azkaban安装与简介,azkaban的简单使用 为什么需要工作流调度系统 一个完整的数据分析系统通常都是由大量任务单元组成: ...
- rest_famework 认证与权限组件
定义个一个认证类 from rest_framework import exceptionsfrom rest_framework.authentication import BaseAuthenti ...
- pyqt------对话框
一 .输入文字 from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit, QInputDialog, QApplication) im ...
- EF_简单的增删改查
EF分为三种code_first,model_first,dabase_first这三种模式,网上的例子有好多,但是用了之后感觉实际中都不是这么用的,此处记录写下来日后用的着了可以快速应用,记录如下: ...
- vue源码逐行注释分析+40多m的vue源码程序流程图思维导图 (diff部分待后续更新)
vue源码业余时间差不多看了一年,以前在网上找帖子,发现很多帖子很零散,都是一部分一部分说,断章的很多,所以自己下定决定一行行看,经过自己坚持与努力,现在基本看完了,差ddf那部分,因为考虑到自己要换 ...
- JS 中offset 的小bug 与解决方案。
一.发现bug准备工作,先定义一个div,然后给div加上样式 效果图如图所示: 二.编写正常的代码,同时给div加上一个id 会发现div图会向左缩进...直至消失. 三.添加代码bo ...
- 移动web图片加载完获取img宽高
1.vue中 @load=function(){} 等待img加载完触发load函数 2.window.load=function(){var imgheight=$(".btnimg& ...
- redis多实例和高可用
实验:多实例节点 10.220.5.65(三个实例) 高可用节点:10.220.5.67 创建目录,将三个实例文件都放在这个目录中 [root@ ~]# yum install redis -y [r ...