#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<climits>
#include<queue>
using namespace std;
typedef long long ll;
int V,E,K;
/*struct kra{
int where;
bool inUse;
kra(int where=0;bool inUse=false):where(where),inUse(inUse){}
}*/
vector<int> G[200050];
int inUse[200050];
bool deleted[200050];
bool visited[200050];
queue<int> Q;
vector<int> last;
vector<int> best;
void wczytaj()
{
cin>>V>>E>>K;
for(int i=0;i<E;i++)
{
int a,b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
inUse[a]++;
inUse[b]++;
}
}
int DFS(int x)
{
last.push_back(x);
int result=1;
visited[x]=true;
for(auto i:G[x])
if(!visited[i]&&!deleted[i])
result+=DFS(i);
return result;
}
int main()
{
ios::sync_with_stdio(0);
wczytaj();
for(int i=1;i<V;i++)
if(inUse[i]<K)
{
Q.push(i);
deleted[i]=true;
}
while(!Q.empty())
{
int now=Q.front();
Q.pop();
for(auto i:G[now])
{
inUse[i]--;
if(inUse[i]<K&&!deleted[i])
{
deleted[i]=true;
Q.push(i);
}
}
}
int result=0;
for(int i=1;i<V;i++)
{
if(!deleted[i]&&!visited[i])
{
int DFSResult=DFS(i);
if(DFSResult>result)
{
result=DFSResult;
best=last;
}
}
}
if(result==0)
{
cout<<"NIE"<<endl;
}
else
{
cout<<result<<endl;
sort(best.begin(),best.end());
for(auto i:best)
cout<<i<<' ';
}
}
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 | #include<iostream> #include<set> #include<vector> #include<algorithm> #include<climits> #include<queue> using namespace std; typedef long long ll; int V,E,K; /*struct kra{ int where; bool inUse; kra(int where=0;bool inUse=false):where(where),inUse(inUse){} }*/ vector<int> G[200050]; int inUse[200050]; bool deleted[200050]; bool visited[200050]; queue<int> Q; vector<int> last; vector<int> best; void wczytaj() { cin>>V>>E>>K; for(int i=0;i<E;i++) { int a,b; cin>>a>>b; G[a].push_back(b); G[b].push_back(a); inUse[a]++; inUse[b]++; } } int DFS(int x) { last.push_back(x); int result=1; visited[x]=true; for(auto i:G[x]) if(!visited[i]&&!deleted[i]) result+=DFS(i); return result; } int main() { ios::sync_with_stdio(0); wczytaj(); for(int i=1;i<V;i++) if(inUse[i]<K) { Q.push(i); deleted[i]=true; } while(!Q.empty()) { int now=Q.front(); Q.pop(); for(auto i:G[now]) { inUse[i]--; if(inUse[i]<K&&!deleted[i]) { deleted[i]=true; Q.push(i); } } } int result=0; for(int i=1;i<V;i++) { if(!deleted[i]&&!visited[i]) { int DFSResult=DFS(i); if(DFSResult>result) { result=DFSResult; best=last; } } } if(result==0) { cout<<"NIE"<<endl; } else { cout<<result<<endl; sort(best.begin(),best.end()); for(auto i:best) cout<<i<<' '; } } |
English