Skip to content

Instantly share code, notes, and snippets.

@surinoel
Last active July 15, 2019 05:20
Show Gist options
  • Save surinoel/d29a1bb83c3067487fa9ee5bc15a9322 to your computer and use it in GitHub Desktop.
Save surinoel/d29a1bb83c3067487fa9ee5bc15a9322 to your computer and use it in GitHub Desktop.
#include <queue>
#include <cstring>
#include <iostream>
using namespace std;
struct tree {
int p;
int left, right;
tree() : p(-1) {}
tree(int p, int left, int right) : p(p), left(left), right(right) {}
};
tree tr[10001];
int coldata[10001];
int col = 1;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int p, l, r;
tr[p].left = l, tr[p].right = r; // CL.exe
tr[l].p = p, tr[r].p = p;
}
int root;
for (int i = 1; i <= n; i++) {
if (tr[i].p == -1) {
root = i;
}
}
cout << root << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment