Submission #1336711

#TimeUsernameProblemLanguageResultExecution timeMemory
1336711SpyrosAlivLaser Strike (EGOI25_laserstrike)C++20
8 / 100
5 ms504 KiB
#include <bits/stdc++.h>
using namespace std;

int n;
vector<vector<int>> tree;

void encrypt() {
    tree.resize(n+1);
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    int root = 0;
    for (int i = 1; i < n; i++) {
        if (tree[i].size() > tree[root].size()) root = i;
    }
    if (root < tree[root][0]) cout << 0 << endl;
    else cout << 1 << endl;
    for (auto nxt: tree[root]) cout << nxt << " ";
    cout << endl;
}

void decrypt() {
    string s; cin >> s;
    int root = -1;
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        if (root == -1) {
            if (s == "0") root = a;
            else root = b;
        }
        cout << (a ^ b ^ root) << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int p; cin >> p >> n;
    if (p == 1) encrypt();
    else decrypt();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...