设为首页 加入收藏

TOP

CSU1660: K-Cycle
2015-11-21 00:59:14 来源: 作者: 【 】 浏览:1
Tags:CSU1660: K-Cycle

Description

A simple cycle is a closed simple path, with no other repeated vertices or edges other than the starting and ending vertices. The length of a cycle is the number of vertices on it. Given an undirected graph G(V, E), you are to detect whether it contains a simple cycle of length K. To make the problem easier, we only consider cases with small K here.

Input

There are multiple test cases.
The first line will contain a positive integer T (T ≤ 10) meaning the number of test cases.
For each test case, the first line contains three positive integers N, M and K ( N ≤ 50, M ≤ 500, 3 ≤ K ≤ 7). N is the number of vertices of the graph, M is the number of edges and K is the length of the cycle desired. Next follow M lines, each line contains two integers A and B, describing an undirected edge AB of the graph. Vertices are numbered from 0 to N-1.

Output

For each test case, you should output “YES” in one line if there is a cycle of length K in the given graph, otherwise output “NO”.

Sample Input

2
6 8 4
0 1
1 2
2 0
3 4
4 5
5 3
1 3
2 4
4 4 3
0 1
1 2
2 3
3 0

Sample Output

YES
NO

HINT

?

Source


题意: 问在一个图里面能否找到一个长度为k的环
思路: 直接搜索看点是否重复访问
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include
         #include 
         
           #include 
          
            #include 
           
             #include 
            
              #include 
             
               #include 
              
                #include 
               
                 using namespace std; #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 200005 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) const int mod = 1e9+7; vector
                
                  a[550]; int vis[550],flag; int n,m,k; void dfs(int now,int pos,int pre) { if(vis[now]) { if(pos-vis[now]==k) flag = 1; return; } if(flag) return; vis[now]=pos; int i,len = a[now].size(); for(i = 0; i
                  
                 
                
               
              
             
            
           
          
         
       
      
     
    
   
  
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 1528 Card Game Cheater (最.. 下一篇POJ 2136 Vertical Histogram

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: