Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- //#define LOCAL
- int n, k;
- int v[100005][2];
- int colors[100005];
- void ReadData()
- {
- scanf("%d", &n);
- memset(v, 0, sizeof(v));
- memset(colors, 0xFF, sizeof(colors));
- int round = 0;
- for(int i = 0; i < n; i++)
- {
- int from, to;
- scanf("%d %d", &from, &to);
- if(i == n / 2)
- round++;
- v[from][round] = to;
- v[to][round] = from;
- }
- scanf("%d", &k);
- }
- int answer;
- void Solve()
- {
- answer = 1;
- int color = 0;
- colors[1] = 0;
- for(int i = 2; i <= n; i++)
- {
- if(colors[i] == -1
- && colors[v[i][0]] != color && colors[v[i][1]] != color)
- {
- colors[i] = color;
- answer++;
- }
- }
- }
- void WriteData()
- {
- if(answer < k)
- {
- printf("0\n");
- return;
- }
- int filled = 0;
- for(int i = 1; i <= n; i++)
- {
- if(colors[i] == 0)
- {
- printf("%d ", i);
- filled++;
- }
- if(filled == k)
- break;
- }
- printf("\n");
- }
- int main()
- {
- int QWE = 1;
- freopen("input.txt", "r", stdin);
- #ifdef LOCAL
- scanf("%d", &QWE);
- #endif
- for(int T = 0; T < QWE; T++)
- {
- ReadData();
- Solve();
- WriteData();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement