#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<bitset>
#include<set>
#include<map>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define all(c) (c).begin(),(c).end()
#define scanf(...) scanf(__VA_ARGS__)?:0
#define eprintf(...) fprintf(stderr,__VA_ARGS__),fflush(stderr)
#define e1 first
#define e2 second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
int n,m,d,a,b,w,s,st[200001];
bool c=false;
bitset<200001> nie,odw;
vector<int> v[200001],zb;
priority_queue<pii,vector<pii>,greater<pii> >pq;
int dfs(int a)
{
odw[a]=true;
if (c) zb.pb(a);
int ret=1;
foreach(it,v[a]) if (!nie[*it] && !odw[*it]) ret+=dfs(*it);
return ret;
}
int main()
{
scanf("%d%d%d",&n,&m,&d);
REP(i,m) scanf("%d%d",&a,&b),v[a].pb(b),v[b].pb(a);
FOR(i,1,n) st[i]=v[i].size(),pq.push(mp(st[i],i));
while (!pq.empty())
{
pii x=pq.top(); pq.pop();
if (x.e1>=d) break;
if (nie[x.e2]) continue;
nie[x.e2]=true;
foreach(it,v[x.e2]) if (!nie[*it]) st[*it]--,pq.push(mp(st[*it],*it));
}
FOR(i,1,n) if (!nie[i] && !odw[i])
{
int u=dfs(i);
if (u>w) w=u,s=i;
}
if (w)
{
odw.reset();
c=true;
dfs(s);
sort(all(zb));
printf("%d\n",w);
foreach(it,zb) printf("%d ",*it);
}
else puts("NIE");
}
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 | #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<cassert> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<bitset> #include<set> #include<map> #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) #define foreach(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++) #define all(c) (c).begin(),(c).end() #define scanf(...) scanf(__VA_ARGS__)?:0 #define eprintf(...) fprintf(stderr,__VA_ARGS__),fflush(stderr) #define e1 first #define e2 second #define mp make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ll,int> pli; typedef pair<int,ll> pil; int n,m,d,a,b,w,s,st[200001]; bool c=false; bitset<200001> nie,odw; vector<int> v[200001],zb; priority_queue<pii,vector<pii>,greater<pii> >pq; int dfs(int a) { odw[a]=true; if (c) zb.pb(a); int ret=1; foreach(it,v[a]) if (!nie[*it] && !odw[*it]) ret+=dfs(*it); return ret; } int main() { scanf("%d%d%d",&n,&m,&d); REP(i,m) scanf("%d%d",&a,&b),v[a].pb(b),v[b].pb(a); FOR(i,1,n) st[i]=v[i].size(),pq.push(mp(st[i],i)); while (!pq.empty()) { pii x=pq.top(); pq.pop(); if (x.e1>=d) break; if (nie[x.e2]) continue; nie[x.e2]=true; foreach(it,v[x.e2]) if (!nie[*it]) st[*it]--,pq.push(mp(st[*it],*it)); } FOR(i,1,n) if (!nie[i] && !odw[i]) { int u=dfs(i); if (u>w) w=u,s=i; } if (w) { odw.reset(); c=true; dfs(s); sort(all(zb)); printf("%d\n",w); foreach(it,zb) printf("%d ",*it); } else puts("NIE"); } |
English