Submission #621476

# Submission time Handle Problem Language Result Execution time Memory
621476 2022-08-03T20:56:26 Z elkernos Travelling Salesperson (CCO20_day2problem1) C++17
0 / 25
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector col(n + 1, vector<bool>(n + 1));
    for(int i = 2; i <= n; i++) {
        for(int j = 1; j < i; j++) {
            char c;
            cin >> c;
            col[i][j] = col[j][i] = (c == 'R');
        }
    }
    for(int s = 1; s <= n; s++) {
        vector<int> one{s}, two;
        for(int i = 1; i <= n; i++) {
            if(i == s) {
                continue;
            }
            if(one.empty() || col[one.back()][i]) {
                one.push_back(i);
            }
            else if(two.empty() || !col[two.back()][i]) {
                two.push_back(i);
            }
            else if(col[one.back()][two.back()]) {
                one.push_back(two.back());
                two.pop_back();
                one.push_back(i);
            }
            else {
                two.push_back(one.back());
                one.pop_back();
                two.push_back(i);
            }
        }
        cout << n << '\n';
        if(!two.empty() && two[0] == s) {
            swap(one, two);
        }
        for(int i : one) {
            cout << i << " ";
        }
        for(int i : two) {
            cout << i << " ";
        }
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -