博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL 1077 Travelling Tours(统计无向图中环的数目)
阅读量:6253 次
发布时间:2019-06-22

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

Travelling Tours

Time limit: 1.0 second
Memory limit: 64 MB
There are
N cities numbered from 1 to
N (1 ≤ 
N ≤ 200) and
M two-way roads connect them. There are at most one road between two cities. In summer holiday, members of DSAP Group want to make some traveling tours. Each tour is a route passes
K different cities (
K > 2)
T
1,
T
2, …,
TK and return to
T
1. Your task is to help them make
T tours such that:
  1. Each of these T tours has at least a road that does not belong to (T−1) other tours.
  2. T is maximum.

Input

The first line of input contains
N and
M separated with white spaces. Then follow by
M lines, each has two number
H and
T which means there is a road connect city
H and city
T.

Output

You must output an integer number
T — the maximum number of tours. If
T > 0, then
T lines followed, each describe a tour. The first number of each line is
K — the amount of different cities in the tour, then
K numbers which represent
K cities in the tour.
If there are more than one solution, you can output any of them.

Sample

input output
5 71 21 31 42 42 33 45 4
33 1 2 43 1 4 34 1 2 3 4
Problem Author: Nguyen Xuan My (Converted by Dinh Quang Hiep and Tran Nam Trung)
【分析】给你一张无向图,问你图中最多存在多少个环。用并查集来做,每次输入一条边,如果两个顶点不在同一集合中,就把他俩合为一个集合中,如果已经在一个集合中了,
说明只要加上这条边,就会形成一个环,然后就BFS找就行了,用pre数组记录路径。
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f#define met(a,b) memset(a,b,sizeof a)#define pb push_backtypedef long long ll;using namespace std;const int N = 205;const int M = 24005;int n,m,k,l,tot=0;int parent[N],pre[N],vis[N];vector
vec[N],ans[N*N];int Find(int x){ if(parent[x]!=x)parent[x]=Find(parent[x]); return parent[x];}void Union(int x,int y){ x=Find(x);y=Find(y); if(x==y)return; else parent[y]=x;}void bfs(int s,int t){ met(vis,0);met(pre,0); queue
q; q.push(s);vis[s]=1; while(!q.empty()){ int u=q.front();q.pop(); if(u==t)return; for(int i=0;i

 

转载于:https://www.cnblogs.com/jianrenfang/p/5997525.html

你可能感兴趣的文章
c#-SimHash匹配相似-算法
查看>>
字符复习
查看>>
Linux系统挂载ntfs分区
查看>>
10.常见数据库操作1
查看>>
JavaScript高级-定义函数(类)方法
查看>>
移动web图片高度自适应的解决方案
查看>>
API
查看>>
需求获取的前期工作(不断更新)
查看>>
10.23
查看>>
hdu5420 Victor and Proposition
查看>>
如何编写可移植的c/c++代码
查看>>
#pragma pack(n)
查看>>
IntelliJ IDEA 2018.3 升级功能介绍
查看>>
基于.NET平台常用的框架整理
查看>>
【每天一道算法题】Lucky String
查看>>
整合apache+tomcat+keepalived实现高可用tomcat集群
查看>>
计算几何-HPI
查看>>
香农熵学习+例子[转载]
查看>>
利用DE2上的WM8731D/A转换器产生正弦波
查看>>
清除EasyUi combotree下拉树的值
查看>>