1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Zadanie: MIS Mistrzostwa [B]
Potyczki Algorytmiczne 2015, runda 2. Dostępna pamięć: 256MB.
*/

#include <iostream>
#include <algorithm>

#include <assert.h> 

//#define FOR0(n) for(int i = 0; i < n; ++ i)
#define FOR1(n) for(int i = 1; i <= n; ++ i)
#define FOR0x(x,n) for(int x = 0; x < n; ++x)


using namespace std;

const int lmax=200000+10;

struct tM { int cnt,first,idx; };
struct tD { int a,b; };
struct tL { int dnr,next; };

int lm,ld,dmin;
tM M[lmax];
tD D[lmax];
tL L[lmax*2];
int A[lmax];

int grupa(int gnr,int m0)
{
	int S=1,a=1, m,m1,n,d;
	
	M[m0].idx=gnr;
	A[a]=m0;

	while(a)
	{
		m=A[a--];
		assert(M[m].idx>=0);
		
		n=M[m].first;
		while(n)
		{
			d=L[n].dnr;
			m1=D[d].a;
			if(m1) FOR1(2)
			{
				if(!M[m1].idx)
				{
					M[m1].idx=gnr;
					A[++a]=m1;
					S++;
				}
				m1=D[d].b;
			}
			
			n=L[n].next;
		}
	}
	
	return S;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);

//============================================================= dane
	cin >>lm >>ld >>dmin;

	FOR1(lm) M[i] = {0,0,0};

	// wczytanie dróg	
	{
		int a,b,l=0;	
		FOR1(ld)
		{
			cin >>a >>b;
			D[i]={a,b};
			FOR0x(j,2)
			{
				L[++l]={i,M[a].first};
				M[a].first=l;
				M[a].cnt++;
				a=b;
			}
		}
	}	
	
//============================================================= eliminacja
	{
		int m,m1,n,d, nA=0;
		FOR1(lm) if (M[i].cnt<dmin) A[++nA]=i; // znajdź outsiderów
		
		// wycinanie dróg
		while(nA)
		{
			m=A[nA--];
			if (M[m].idx<0) continue;
			M[m].idx = -1;
			
			n=M[m].first;
			while(n)
			{
				d=L[n].dnr;
				m1=D[d].a;
				if(m1) 
				{
					if (m1==m) m1=D[d].b;
					if ((--M[m1].cnt)<dmin)
						A[++nA]=m1;
					D[d].a = D[d].b = 0;
				}
				n=L[n].next;
			}
		}
	}
//============================================================= analiza
	{
		int IDX,idx=0;
		int CNT=0,cnt;
		FOR1(lm) if(M[i].idx==0)
		{
			cnt=grupa(++idx,i);
			if (cnt>CNT)
			{
				CNT=cnt;
				IDX=idx;
			}
		}
		
		if(!CNT)
			cout <<"NIE";
		else
		{
			cout <<CNT <<endl;

			cnt=CNT;
			FOR1(lm) 
				if(M[i].idx==IDX) 
				{
					cout <<i<<" ";
/*					if(--cnt)
						cout << " ";
					else
						cout <<endl;
						*/
				}
		}
	}
	
//FOR1(lm) cout <<i<<" c:"<<M[i].cnt<<" x:"<<M[i].idx<<" f:"<<M[i].first<<endl;
}