HDU 5631 Rikka with Graph
如果原图不连通,直接输出0.
如果原图连通,删除X条边之后要保证新图连通,再看数据是n+1条边-->因此,最多只能删去两条边。
因为n=100,可以枚举进行验证,枚举删去每一条边是否连通,枚举删去每两条边是否连通,验证是否连通可以用并查集,可以BFS。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std; const int maxn=+;
int n;
int fa[maxn];
int u[maxn],v[maxn];
long long c[maxn][maxn];
int T;
int ans; int Find(int x)
{
if(x!=fa[x]) fa[x]=Find(fa[x]);
return fa[x];
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); ans=;
for(int i=;i<=n+;i++)
scanf("%d%d",&u[i],&v[i]); for(int i=;i<=n;i++) fa[i]=i;
int un=n;
for(int i=;i<=n+;i++)
{
int fu=Find(u[i]);
int fv=Find(v[i]);
if(fu!=fv)
{
un--;
fa[fu]=fv;
}
} if(un!=) ans=;
else
{
for(int i=;i<=n+;i++)
{
for(int k=;k<=n;k++) fa[k]=k;
un=n;
for(int k=;k<=n+;k++)
{
if(k==i) continue;
int fu=Find(u[k]);
int fv=Find(v[k]);
if(fu!=fv)
{
un--;
fa[fu]=fv;
}
}
if(un==) ans=ans+;
} for(int i=;i<=n+;i++)
{
for(int j=i+;j<=n+;j++)
{
for(int i=;i<=n;i++) fa[i]=i;
un=n;
for(int k=;k<=n+;k++)
{
if(k==i||k==j) continue;
int fu=Find(u[k]);
int fv=Find(v[k]);
if(fu!=fv)
{
un--;
fa[fu]=fv;
}
}
if(un==) ans=ans+;
}
}
}
printf("%d\n",ans);
}
return ;
}
HDU 5631 Rikka with Graph的更多相关文章
- HDU 5631 Rikka with Graph 暴力 并查集
Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...
- hdu 5631 Rikka with Graph(图)
n个点最少要n-1条边才能连通,可以删除一条边,最多删除2条边,然后枚举删除的1条边或2条边,用并查集判断是否连通,时间复杂度为O(n^3) 这边犯了个错误, for(int i=0;i<N;i ...
- HDU 5422 Rikka with Graph
Rikka with Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 6090 Rikka with Graph
Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- HDU 5424——Rikka with Graph II——————【哈密顿路径】
Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 6090 Rikka with Graph —— 2017 Multi-University Training 5
Rikka with Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu 5424 Rikka with Graph II(dfs+哈密顿路径)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so h ...
- hdu 5422 Rikka with Graph(简单题)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- 2017ACM暑期多校联合训练 - Team 5 1006 HDU 5205 Rikka with Graph (找规律)
题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...
随机推荐
- UVa11235 RMQ
input 1<=n,q<=100000 升序序列a1 a2 a3 ... an -100000<=ai<=100000 q行i j 1<=i,j<=n 输入结束标 ...
- lucene3.6.1 经典案例 入门教程 (包含从文件中读取content)
转载http://liqita.iteye.com/blog/1676664 第一步:下载lucene的核心包 lucene-core-3.6.1-javadoc.jar (3.5 MB) lucen ...
- Lucene4.X 高级应用
Lucene 简介以及使用 Lucene, 一个基于 Java 的开源的全文搜索工具包,可以方便的嵌入到各种应用系统中,实现针对应用的全文索引以及检索功能.目前是 Apache jakarta 项目 ...
- 解析GenericOptionsParser
hadoop源代码分析(4)-org.apache.hadoop.util包-GenericOptionsParser类[原创] 一 准备 hadoop版本:1.0.3,GenericOptio ...
- Windows下MongoDB安装及创建用户名和密码
下载MongoDB的安装文件https://www.mongodb.com/download-center#community,选择合适的版本(注:本人选择的是3.2.6) 下载完MongoDB.ms ...
- Chapter 1 First Sight——19
"I'm headed toward building four, I could show you the way…" Definitely over-helpful. &quo ...
- asp.net C# 题目大全
net001在线饰品销售系统 net002鲜花商城 net003商品销售管理系统 net004在线辅导答疑 net005土地税务管理系统 net006旅游管理 net007房产中介 net008房产信 ...
- hdu_3549_Flow Problem(最大流)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 题意:求1到n的最大流 题解:模版题,直接上Claris的ISAP,效率是一般dfs的十倍,OR ...
- shortcut to open a linux terminal
1) alt+ f2 2) input "gnome-terminal" 3) press "enter"
- 1.3 selenium IDE录制脚本转换为其他代码格式
1.在seleniumIDE录制框中点击Options->options... 在Enable experimental features前打对勾,点击确定.