HDU 5483 Nux Walpurgis
Nux Walpurgis
This problem will be judged on HDU. Original ID: 5483
64-bit integer IO format: %I64d Java class name: Main
Input
The first line of the input is a integer T, meaning that there are T test cases.
Every test cases begin with a integer n ,which is the number of vertexes of this graph.
Then n−1 lines follow, the ith line contain n−i integers, the jth number w in this line represents the weight between vertex i and vertex i+j.
1≤T≤20.
1≤n,w≤3,000.
Output
Sample Input
2
3
1 1
1
4
2 2 3
2 2
3
Sample Output
0
1
Source
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int,int>;
const int maxn = ;
int head[maxn],uf[maxn],dfn[maxn],low[maxn],clk,tot,ret;
struct arc {
int to,next;
arc(int x = ,int z = -) {
to = x;
next = z;
}
} e[];
vector<PII>g[maxn];
void add(int u,int v) {
e[tot] = arc(v,head[u]);
head[u] = tot++;
}
int Find(int x) {
if(x != uf[x]) uf[x] = Find(uf[x]);
return uf[x];
}
void tarjan(int u,int fa) {
dfn[u] = low[u] = ++clk;
bool flag = true;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].to == fa && flag) {
flag = false;
continue;
}
if(!dfn[e[i].to]) {
tarjan(e[i].to,u);
low[u] = min(low[u],low[e[i].to]);
if(low[e[i].to] > dfn[u]) ++ret;
} else low[u] = min(low[u],dfn[e[i].to]);
}
}
int main() {
int kase,n;
scanf("%d",&kase);
while(kase--) {
scanf("%d",&n);
for(int i = ret = ; i < maxn; ++i) {
uf[i] = i;
g[i].clear();
}
for(int i = ,tmp; i < n; ++i) {
for(int j = i + ; j <= n; ++j) {
scanf("%d",&tmp);
g[tmp].push_back(PII(i,j));
}
}
for(int i = ; i < maxn; ++i) {
memset(dfn,,sizeof dfn);
memset(head,-,sizeof head);
tot = ;
for(int j = g[i].size()-; j >= ; --j) {
int u = Find(g[i][j].first);
int v = Find(g[i][j].second);
if(u != v) {
add(u,v);
add(v,u);
}
}
for(int j = ; j <= n; ++j)
if(!dfn[j]) tarjan(j,-);
for(int j = g[i].size()-; j >= ; --j) {
int u = Find(g[i][j].first);
int v = Find(g[i][j].second);
if(u != v) uf[u] = v;
}
}
printf("%d\n",ret);
}
return ;
}
HDU 5483 Nux Walpurgis的更多相关文章
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 在CentOS或RHEL上安装Nux Dextop仓库
介绍 Nux Dextop是类似CentOS.RHEL.ScientificLinux的第三方RPM仓库(比如:Ardour,Shutter等等).目前,Nux Dextop对CentOS/RHEL ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
随机推荐
- asp.net调试技巧
一眨眼的功夫,自己已经学习asp.net的有一年的功夫了.虽然称不上什么大神,但是也有一点知识的积累.就写一片调试的入门文章给那些刚刚入门迷茫的童鞋们.希望你学习了我这篇文章能从迷茫的生活中找回编程的 ...
- python部分 + 数据库 + 网络编程
PS:附上我的博客地址,答案中略的部分我的博客都有,直接原标题搜索即可.https://www.cnblogs.com/Roc-Atlantis/ 第一部分 Python基础篇(80题) 为什么学习P ...
- Oracle数据仓库创建教程
Oracle数据仓库创建教程.如何创建一个数据仓库,创建实例,以为毕业设计要求,最近开始Oracle的数仓建模实践,详细记录了图形界面下的 Oracle database 12C 数据仓库创建过程. ...
- Jquery AJAX使用踩坑小记
在使用jquery ajax时,如果其参数是一个json对象,将此参数使用$('#dd').data(param)绑定到一个元素上, 在使用$('#dd').bind('click',function ...
- 【Web应用-大文件部署】上传超过 2M 的文件到 Azure PHP 网站失败
问题描述 上传超过 2M 的文件到 Azure PHP 网站失败. 问题分析 由于 PHP 本身默认上传文件的上限是 2M,所以当上传超过2M的文件时会报错. 解决方法 根据以下步骤进行配置: 在 s ...
- Linux中配置系统参数
[root@localhost ~]# vim /etc/security/limits.conf root soft nofile 65535root hard nofile 65535* soft ...
- VS2010中C++ 出现fatal error LNK1169: 找到一个或多个多重定义的符号
一般是函数重定义造成的 例如定义了两个 sum(x,y)函数
- 对于exacoin虚拟币以及其他虚拟币乱象的思考
今天晚上12点正,我帮两个朋友购买exacoin虚拟币,当然我也购买,为了购买我做了充分的准备,包括使用多个浏览器和准备良好的***代理,并转如足量BTC以支持购买,但是通过三天晚上的奋战,让我感觉这 ...
- spark 的RDD各种转换和动作
今天先把spark的各种基本转换和动作总结下,以后有时间把各种用法放上去. 1 RDD基本转换操作 map.flagMap.distinct coalesce.repartition coale ...
- SQL与脚本语言
SQL是人类与数据库沟通的语言https://zhidao.baidu.com/question/413397944.html我个人认为SQL是一种专门对数据库进行操作的特殊的脚本语言.因为SQL语句 ...