Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define nl "\n"
- void files(){
- ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- void solve(){
- int n; cin>>n;
- int s; cin>>s;
- vector<bool> vis(n+1, false);
- stack<int> st;
- vis[s] = true;
- st.push(s);
- int k; cin>>k;
- vector<int> child(k);
- for(int i=0; i<k; i++){
- cin>>child[i];
- }
- vis[child[0]] = true;
- st.push(child[0]);
- bool ok = false;
- while(!st.empty()){
- int x = st.top();
- cout<<"> "<<x<<endl;
- cout.flush();
- cin>>k;
- if(k<=0) return;
- child = vector<int>();
- for(int i=0; i<k; i++){
- int y; cin>>y;
- if(!vis[y]){
- child.push_back(y);
- }
- }
- if(child.size() == 0){
- st.pop();
- continue;
- }
- vis[child[0]] = true;
- st.push(child[0]);
- }
- }
- int main(){
- files();
- int t = 1;
- // cin>>t;
- while(t--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement