如果原图不连通,直接输出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的更多相关文章

  1. HDU 5631 Rikka with Graph 暴力 并查集

    Rikka with Graph 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5631 Description As we know, Rikka ...

  2. hdu 5631 Rikka with Graph(图)

    n个点最少要n-1条边才能连通,可以删除一条边,最多删除2条边,然后枚举删除的1条边或2条边,用并查集判断是否连通,时间复杂度为O(n^3) 这边犯了个错误, for(int i=0;i<N;i ...

  3. HDU 5422 Rikka with Graph

    Rikka with Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. HDU 6090 Rikka with Graph

    Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  5. HDU 5424——Rikka with Graph II——————【哈密顿路径】

    Rikka with Graph II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  6. 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) ...

  7. 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 ...

  8. hdu 5422 Rikka with Graph(简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  9. 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 ...

随机推荐

  1. C++ 字符串字面值

    C++ 字符串字面值 C++ 基本字符串类型 C++ 字符串类型 char 和 wchar_t c11 新增了 char16_t 和 char32_t 例子: wchat_t title[] = L& ...

  2. OpenGL—Android 开机动画源码分析二

    引自http://blog.csdn.net/luoshengyang/article/details/7691321/ BootAnimation类的成员函数的实现比较长,我们分段来阅读: 第三个开 ...

  3. OpenCV 基础知识------图像创建、访问、转换

    cvCreateImage函数-- Cxcore数组操作 创建头并分配数据 IplImage* cvCreateImage( CvSize size, int depth, int channels ...

  4. sqlserver2008行锁

    select * from tablename WITH (UPDLOCK) where Id=#value#

  5. FRP 浅析

    一.Reactive? 请先看一个非常简单的小应用,它允许用户在一个搜索输入框里输入关键词,然后在其下方的结果区域实时显示从Flicker网站搜索得到的图片,当用户输入的关键词发生变化,显示的图片也会 ...

  6. html5 localStorage和sessionStorage

    该随便来自: http://www.cnblogs.com/yuzhongwusan/archive/2011/12/19/2293347.html html5中的Web Storage包括了两种存储 ...

  7. android平台菜单返回键监听

    //声明 void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event); //实现 //按键控制(检测onKeyReleased有反 ...

  8. Git学习 -- 冲突解决

    当连个分支对统一文件提交了不同修改时,可能会出现冲突,例如: $ git merge feature1 Auto-merging readme.txt CONFLICT (content): Merg ...

  9. CodeForces 678C Joty and Chocolate

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  10. java反射简解

    1.首先一个问题,什么是类,类是不是对象? 我们总是说我们new一个对象出来 那么我们还没有new的时候,建造的那个java类是不是对象呢? 是 它是java.lang.Class的对象 对于反射我们 ...