fork download
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<iostream>
  6. #include<fstream>
  7. #include<map>
  8. #include<ctime>
  9. #include<set>
  10. #include<queue>
  11. #include<cmath>
  12. #include<vector>
  13. #include<bitset>
  14. #include<functional>
  15. #define x first
  16. #define y second
  17. #define mp make_pair
  18. #define pb push_back
  19. #define REP(i,l,r) for((i)=(l);(i)<=(r);++(i))
  20. #define REP2(i,l,r) for((i)=(l);(i)!=(r);++(i))
  21. using namespace std;
  22.  
  23. typedef long long LL;
  24. typedef double ld;
  25.  
  26. //选取不超过k个点,使得所有点被支配。。
  27. //这不是竞赛图
  28.  
  29. //如果一定能够被k个点全部控制。。
  30. //那么其实只要控制了这k个点就行了。。
  31. //所以完全可以贪心。。
  32.  
  33. const int MAX=4000000+10;
  34.  
  35. int n,m,k;
  36. int begin[MAX],begin2[MAX],t[MAX],next[MAX],tot;
  37. int hash[MAX];
  38.  
  39. void add(int begin[MAX],int a,int b)
  40. {
  41. t[++tot]=b;
  42. next[tot]=begin[a];
  43. begin[a]=tot;
  44. }
  45.  
  46. int ans[MAX],top;
  47.  
  48. int main()
  49. {
  50. #ifndef ONLINE_JUDGE
  51. // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  52. #endif
  53. int i;
  54. scanf("%d%d%d",&n,&m,&k);
  55. REP(i,1,m)
  56. {
  57. int a,b;
  58. scanf("%d%d",&a,&b);
  59. add(begin,a,b);
  60. add(begin,b,a);
  61.  
  62. add(begin2,a,b);
  63. add(begin2,b,a);
  64. }
  65. REP(i,1,n)
  66. if(!hash[i])
  67. {
  68. ans[++top]=i;
  69. hash[i]=1;
  70. int j,k;
  71. for(j=begin[i];j;j=next[j])
  72. {
  73. int v=t[j];
  74. hash[v]=1;
  75. for(k=begin2[v];k;k=next[k])
  76. {
  77. int vv=t[k];
  78. hash[vv]=1;
  79. }
  80. begin2[v]=0;
  81. }
  82. }
  83. printf("%d\n",top);
  84. REP(i,1,top)
  85. printf("%d ",ans[i]);
  86. printf("\n");
  87. return 0;
  88. }
  89.  
Success #stdin #stdout 0s 97024KB
stdin
9 8 3
1 2
2 3
3 4
1 4
3 5
4 6
7 8
8 9
stdout
3
1 5 7