# BIO 2018 Round 2 Problem 2 - Best Of Show

Feb 14th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <list>
3. #include <vector>
4.
5. using namespace std;
6.
7. int main() {
8.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
9.     int n; cin >> n;
10.     vector< vector<bool> > matrix(1+n, vector<bool>(1+n));
11.     for (int i = 0; i < n*(n-1)/2; ++i) {
12.         int w, l; cin >> w >> l;
13.         matrix[w][l] = false;
14.         matrix[l][w] = true;
15.     }
16.
17.     list<int> order;
18.     order.insert(order.end(), 1);
19.     for (int i = 2; i <= n; ++i) {
20.         bool found = false;
21.         for (list<int>::iterator it = order.begin(); it != order.end() && !found; ++it) {
22.             int j = *it;
23.             if (matrix[i][j]) {
24.                 found = true;
25.                 order.insert(it, i);
26.             }
27.         }
28.         if (!found) order.insert(order.end(), i);
29.     }
30.
31.     for (int i : order) cout << i << ' ';
32.     cout << endl;
33.     return 0;
34. }
35.