#include<bits/stdc++.h>
using namespace std;
int c=0,d=0,e=0,f=0;
vector<int> graf[200009];
int wie[200009];
int col[200009];
vector<int> wyn[2000009];
void DFS(int u)
{
col[u]=1;
c++;
wyn[d].push_back(u);
for(int i=0; i<graf[u].size(); i++)
{
int v=graf[u][i];
if(wie[v]!=0 && col[v]==0) DFS(v);
}
return;
}
int main()
{
int n,m,p,a,b;
scanf("%d%d%d", &n, &m, &p);
for(int i=1; i<=m; i++)
{
scanf("%d%d", &a, &b);
graf[a].push_back(b);
graf[b].push_back(a);
}
for(int i=1; i<=n; i++) wie[i]=graf[i].size();
queue<int> q;
for(int i=1; i<=n; i++) if(wie[i]<p) q.push(i);
while(!q.empty())
{
a=q.front();
q.pop();
if(wie[a]!=0)
{
wie[a]=0;
for(int i=0; i<graf[i].size(); i++)
{
if(wie[i]!=0)
{
wie[i]--;
if(wie[i]<p) q.push(i);
}
}
}
}
for(int i=1; i<=n; i++)
{
if(wie[i]>0 && col[i]==0) DFS(i);
if(c>e)
{
f=d;
e=c;
}
c=0;
d++;
}
if(e<=1)
{
printf("NIE");
return 0;
}
printf("%d\n", e);
sort(wyn[f].begin(), wyn[f].end());
for(int i=0; i<wyn[f].size(); i++) printf("%d ", wyn[f][i]);
return 0;
}
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 | #include<bits/stdc++.h> using namespace std; int c=0,d=0,e=0,f=0; vector<int> graf[200009]; int wie[200009]; int col[200009]; vector<int> wyn[2000009]; void DFS(int u) { col[u]=1; c++; wyn[d].push_back(u); for(int i=0; i<graf[u].size(); i++) { int v=graf[u][i]; if(wie[v]!=0 && col[v]==0) DFS(v); } return; } int main() { int n,m,p,a,b; scanf("%d%d%d", &n, &m, &p); for(int i=1; i<=m; i++) { scanf("%d%d", &a, &b); graf[a].push_back(b); graf[b].push_back(a); } for(int i=1; i<=n; i++) wie[i]=graf[i].size(); queue<int> q; for(int i=1; i<=n; i++) if(wie[i]<p) q.push(i); while(!q.empty()) { a=q.front(); q.pop(); if(wie[a]!=0) { wie[a]=0; for(int i=0; i<graf[i].size(); i++) { if(wie[i]!=0) { wie[i]--; if(wie[i]<p) q.push(i); } } } } for(int i=1; i<=n; i++) { if(wie[i]>0 && col[i]==0) DFS(i); if(c>e) { f=d; e=c; } c=0; d++; } if(e<=1) { printf("NIE"); return 0; } printf("%d\n", e); sort(wyn[f].begin(), wyn[f].end()); for(int i=0; i<wyn[f].size(); i++) printf("%d ", wyn[f][i]); return 0; } |
English