Advertisement
Elun

Untitled

Jul 16th, 2013
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //#define LOCAL
  5.  
  6. int n, k;
  7. int v[100005][2];
  8. int colors[100005];
  9.  
  10. void ReadData()
  11. {
  12.   scanf("%d", &n);
  13.   memset(v, 0, sizeof(v));
  14.   memset(colors, 0xFF, sizeof(colors));
  15.   int round = 0;
  16.   for(int i = 0; i < n; i++)
  17.   {
  18.     int from, to;
  19.     scanf("%d %d", &from, &to);
  20.     if(i == n / 2)
  21.       round++;
  22.     v[from][round] = to;
  23.     v[to][round] = from;
  24.   }
  25.   scanf("%d", &k);
  26. }
  27.  
  28. int answer;
  29.  
  30. void Solve()
  31. {
  32.   answer = 1;
  33.   int color = 0;
  34.   colors[1] = 0;
  35.   for(int i = 2; i <= n; i++)
  36.   {
  37.     if(colors[i] == -1
  38.       && colors[v[i][0]] != color && colors[v[i][1]] != color)
  39.     {
  40.       colors[i] = color;
  41.       answer++;
  42.     }
  43.   }
  44. }
  45.  
  46. void WriteData()
  47. {
  48.   if(answer < k)
  49.   {
  50.     printf("0\n");
  51.     return;
  52.   }
  53.   int filled = 0;
  54.   for(int i = 1; i <= n; i++)
  55.   {
  56.     if(colors[i] == 0)
  57.     {
  58.       printf("%d ", i);
  59.       filled++;
  60.     }
  61.     if(filled == k)
  62.       break;
  63.   }
  64.   printf("\n");
  65. }
  66.  
  67. int main()
  68. {
  69.   int QWE = 1;
  70.   freopen("input.txt", "r", stdin);
  71. #ifdef LOCAL
  72.   scanf("%d", &QWE);
  73. #endif
  74.   for(int T = 0; T < QWE; T++)
  75.   {
  76.     ReadData();
  77.     Solve();
  78.     WriteData();
  79.   }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement