Johnny Solving

http://codeforces.com/contest/1104/problem/E

 

E. Johnny Solving

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Today is tuesday, that means there is a dispute in JOHNNY SOLVING team again: they try to understand who is Johnny and who is Solving. That's why guys asked Umnik to help them. Umnik gave guys a connected graph with nn vertices without loops and multiedges, such that a degree of any vertex is at least 33, and also he gave a number 1≤k≤n1≤k≤n. Because Johnny is not too smart, he promised to find a simple path with length at least nknk in the graph. In reply, Solving promised to find kk simple by vertices cycles with representatives, such that:

  • Length of each cycle is at least 33.
  • Length of each cycle is not divisible by 33.
  • In each cycle must be a representative - vertex, which belongs only to this cycle among all printed cycles.

You need to help guys resolve the dispute, for that you need to find a solution for Johnny: a simple path with length at least nknk (nn is not necessarily divided by kk), or solution for Solving: kk cycles that satisfy all the conditions above. If there is no any solution - print −1−1.

Input

The first line contains three integers nn, mm and kk (1≤k≤n≤2.5⋅105,1≤m≤5⋅1051≤k≤n≤2.5⋅105,1≤m≤5⋅105)

Next mm lines describe edges of the graph in format vv, uu (1≤v,u≤n1≤v,u≤n). It's guaranteed that v≠uv≠u and all mm pairs are distinct.

It's guaranteed that a degree of each vertex is at least 33.

Output

Print PATH in the first line, if you solve problem for Johnny. In the second line print the number of vertices in the path cc (c≥nkc≥nk). And in the third line print vertices describing the path in route order.

Print CYCLES in the first line, if you solve problem for Solving. In the following lines describe exactly kk cycles in the following format: in the first line print the size of the cycle cc (c≥3c≥3). In the second line print the cycle in route order. Also, the first vertex in the cycle must be a representative.

Print −1−1 if there is no any solution. The total amount of printed numbers in the output must be at most 106106. It's guaranteed, that if exists any solution then there is a correct output satisfies this restriction.

Examples

input

Copy

4 6 2
1 2
1 3
1 4
2 3
2 4
3 4

output

Copy

PATH
4
1 2 3 4 

input

Copy

10 18 2
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 3
3 4
2 4
5 6
6 7
5 7
8 9
9 10
8 10

output

Copy

CYCLES
4
4 1 2 3 
4
7 1 5 6 

可以证明情况一不存在是情况二一定可行

代码:
 

#include<bits/stdc++.h>
#define MAXN 250005
using namespace std;
int n,m,k,len,tot,head[MAXN],qu[MAXN],id[MAXN],cnt,vis[MAXN];
struct edge
{
	int u,v,nxt;
}edg[MAXN<<2];
inline void addedg(int u,int v)
{
	edg[tot].u = u;
	edg[tot].v = v;
	edg[tot].nxt = head[u];
	head[u] = tot++;
}
bool dfs1(int u,int fa)
{
	if(cnt == len)
		return true;
	for(int i = head[u];i != -1;i = edg[i].nxt)
	{
		int v = edg[i].v;
		if(v != fa && !vis[v])
		{
			qu[cnt++] = v;
			vis[v] = 1;
			if(dfs1(v,u))
				return true;
			--cnt;
		}
	}
	return false;
}
void dfs2(int u,int fa)
{
	int flag = 0;
	if(k == 0)
		return;
	for(int i = head[u];i != -1;i = edg[i].nxt)
	{
		int v = edg[i].v;
		if(v != fa && !vis[v])
		{
			flag = 1;
			qu[cnt] = v;
			id[v] = cnt;
			vis[v] = 1;
			++cnt;
			dfs2(v,u);
			--cnt;
		}
	}
	if(!flag)
	{
		int fa1 = -1,fa2 = -1;
		for(int i = head[u];i != -1;i = edg[i].nxt)
		{
			int v = edg[i].v;
			if(v != fa)
			{
				if(fa1 == -1)
					fa1 = v;
				else
				{
					fa2 = v;
					break;
				}
			}
		}
		if(id[fa1] < id[fa2])
			swap(fa1,fa2);
		flag = 0;
		if((id[u] - id[fa1] + 1) % 3)
			flag = fa1;
		else if((id[u] - id[fa2] + 1) % 3)
			flag = fa2;
		if(flag)
		{
			len = id[u] - id[flag] + 1;
			printf("%d\n",len);
			for(int i = id[u];i >= id[flag];--i)
				printf("%d ",qu[i]);
			printf("\n");
			--k;
		}
		else
		{
			len = id[fa1] - id[fa2] + 2;
			printf("%d\n",len);
			printf("%d ",u);
			for(int i = id[fa1];i >= id[fa2];--i)
				printf("%d ",qu[i]);
			printf("\n");
			--k;
		}
	}
}
			
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	memset(head,-1,4 * n + 4);
	tot = cnt = 0;
	int u,v;
	for(int i = 1;i <= m;++i)
	{
		scanf("%d%d",&u,&v);
		addedg(u,v);
		addedg(v,u);
	}
	len = n / k;
	if(n%k)
		++len;
	vis[1] = 1;
	qu[cnt++] = 1;
	if(dfs1(1,1))
	{
		printf("PATH\n%d\n",len);
		for(int i = 0;i < cnt;++i)
			printf("%d ",qu[i]);
	}
	else
	{
		memset(vis,0,4*n+4);
		cnt = 0;
		printf("CYCLES\n");
		qu[cnt++] = 1;
		id[1] = 0;
		vis[1] = 1;
		dfs2(1,1);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值