Untitled
unknown
c_cpp
3 years ago
821 B
4
Indexable
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; vector<int> ln, rn; int a; void print(int node=1){ if (node == -1) return; print(ln[node]); cout << node << " "; print(rn[node]); if (node == 1) cout << endl; } void fun(int p=1, int node=1) { if (node == -1) return; if (p % a == 0) { swap(ln[node],rn[node]); } fun(p+1, ln[node]); fun(p+1, rn[node]); } int main() { int n; cin>>n; ln.push_back(0); rn.push_back(0); while(n--){ int c, d; cin>>c>>d; ln.push_back(c); rn.push_back(d); } cin>>n; while(n--){ cin >> a; fun(); print(); } return 0; }
Editor is loading...