博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5631 Rikka with Graph(无向图去边搜索)
阅读量:4137 次
发布时间:2019-05-25

本文共 2509 字,大约阅读时间需要 8 分钟。

Rikka with Graph

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 905 Accepted Submission(s): 404
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:
Yuta has a non-direct graph with n vertices and n+1 edges. Rikka can choose some of the edges (at least one) and delete them from the graph.
Yuta wants to know the number of the ways to choose the edges in order to make the remaining graph connected.
It is too difficult for Rikka. Can you help her?
Input
The first line contains a number
T(T30) ——The number of the testcases.
For each testcase, the first line contains a number
n(n100) .
Then n+1 lines follow. Each line contains two numbers
u,v , which means there is an edge between u and v.
Output
For each testcase, print a single number.
Sample Input
131 22 33 11 3
Sample Output
9
Source
/*思路:题目意思是一个n个点的无向图,给你n+1条边,求有多少种删除办法,使得图还能连通至少删除一条边我的思路是,n个点,要连通,至少是n-1条边,所以最多删除2条,枚举每一条边,删除求连通若可以,+1,尝试枚举下一条边被删,看能不能继续连通 */  /*  超时   没用邻接表  复杂度O(n*n)的递归  */  /*#include
#include
using namespace std;const int N=100+5;struct Node{ int x,y;}node[N];int check; int map[N][N]; //记录边数 用int可以累加 bool book[N];int n;void dfs(int now){ //深搜 book[now]=1; check++; for(int i=1;i<=n;i++){ //这里时间复杂度n^2 if(book[i]) continue; if(map[now][i]>0) dfs(i); }}int main(){ int t,re; cin>>t; while(t--){ re=0; cin>>n; memset(map,0,sizeof(map)); for(int i=0;i
>node[i].x>>node[i].y; map[node[i].x][node[i].y]++; map[node[i].y][node[i].x]++; } for(int i=0;i
#include
#include
#include
using namespace std;const int N=100+5;struct Node{ int x,y;}node[N];vector
ve[N];int map[N][N]; //记录边数 用int可以累加 bool book[N];int check; int n;void dfs(int now){ //深搜 book[now]=1; check++; for(int i=0;i
0) dfs(ve[now][i]); }}//用一个全局变量减少判断,复杂度减少O(n)//inline bool check(){ //求连通 // for(int i=1;i<=n;i++)// if(!book[i])// return false; // return true;//}int main(){ int t,re; scanf("%d",&t); while(t--){ re=0; scanf("%d",&n); memset(map,0,sizeof(map)); for(int i=1;i<=n;i++){ ve[i].clear(); } for(int i=0;i
>node[i].x>>node[i].y; ve[node[i].x].push_back(node[i].y); ve[node[i].y].push_back(node[i].x); map[node[i].x][node[i].y]++; map[node[i].y][node[i].x]++; } memset(book,0,sizeof(book)); check=0; dfs(1); if(check!=n){ printf("0\n"); continue; } for(int i=0;i

转载地址:http://ydmvi.baihongyu.com/

你可能感兴趣的文章
Pentaho 开发: 在eclipse中构建Pentaho BI Server工程
查看>>
JSP的内置对象及方法
查看>>
android中SharedPreferences的简单例子
查看>>
android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
查看>>
andorid里关于wifi的分析
查看>>
Spring MVC和Struts2的比较
查看>>
Hibernate和IBatis对比
查看>>
Spring MVC 教程,快速入门,深入分析
查看>>
Android 的source (需安装 git repo)
查看>>
Commit our mod to our own repo server
查看>>
LOCAL_PRELINK_MODULE和prelink-linux-arm.map
查看>>
Simple Guide to use the gdb tool in Android environment
查看>>
Netconsole to capture the log
查看>>
Build GingerBread on 32 bit machine.
查看>>
How to make SD Card world wide writable
查看>>
Detecting Memory Leaks in Kernel
查看>>
Linux initial RAM disk (initrd) overview
查看>>
Timestamping Linux kernel printk output in dmesg for fun and profit
查看>>
There's Much More than Intel/AMD Inside
查看>>
apache和tomcat整合
查看>>