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 ...
随机推荐
- oracle 直接连接到数据库 CMD窗口
打开cmd 在命令行 中输入如下命令 sqlplus sys/zd****!@60.**.203/orcl as sysdba 就直接连上了
- hdoj薛猫猫杯程序设计网络赛1003 球球大作战
思路: 二分,check函数不是很好写. 实现: 1. #include <bits/stdc++.h> using namespace std; typedef long long ll ...
- uvm_reg_item——寄存器模型(五)
uvm_reg_item 扩展自uvm_sequence_item,也就说寄存器模型定义了transaction item. adapter 的作用是把这uvm_reg_item转换成uvm_sequ ...
- selenium-Python之鼠标事件
通过click()来模拟鼠标的单击操作,鼠标还具有鼠标右击,双击,悬停甚至鼠标拖动等功能.在webdriver中,将这些鼠标操作方法封装在ActionChains类提供. ActionChains类提 ...
- 原创 :xftp SFTP子系统申请已拒绝 请确保SSH链接的SFTP子系统设置有效
在出现这个错误时候 如果你的远程连接没有问题 那么就执行下面的命令 service sshd restart 搞定!
- Data truncation: Data too long for column 'id' at row 1
Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'titleimg' at ro ...
- mac文件夹怎么重命名?苹果电脑文件夹重命名快捷键
windows系统下给文件夹重命名相信很多朋友都很熟悉,那么Mac OS系统怎么给文件重命名呢,相信很多刚刚入手Mac OS系统的亲们都会有次疑问,下面小编告诉你Mac OS系统的文件夹到底要怎样才能 ...
- Codeforces Round #274 (Div. 2)-C. Exams
http://codeforces.com/contest/479/problem/C C. Exams time limit per test 1 second memory limit per t ...
- thinkphp网站后门-发现后门(Webshell)文件
不知道能不能解决, 1.登录阿里云后台,找到后门文件删除 2.执行 中国镜像 composer config -g repo.packagist composer https://packagist. ...
- JAVA遍历map元素
第一种: Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Ma ...