Advertisement
Ahmed_Negm

Untitled

Apr 8th, 2024
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define nl "\n"
  6.  
  7. void files(){
  8.     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
  9.     #ifndef ONLINE_JUDGE
  10.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  11.     #endif
  12. }
  13.  
  14.  
  15. void solve(){
  16.  
  17.     int n; cin>>n;
  18.     int s; cin>>s;
  19.     vector<bool> vis(n+1, false);
  20.     stack<int> st;
  21.     vis[s] = true;
  22.     st.push(s);
  23.     int k; cin>>k;
  24.     vector<int> child(k);
  25.     for(int i=0; i<k; i++){
  26.         cin>>child[i];
  27.     }
  28.     vis[child[0]] = true;
  29.     st.push(child[0]);
  30.     bool ok = false;
  31.     while(!st.empty()){
  32.         int x = st.top();
  33.         cout<<"> "<<x<<endl;
  34.         cout.flush();
  35.         cin>>k;
  36.         if(k<=0) return;
  37.         child = vector<int>();
  38.         for(int i=0; i<k; i++){
  39.             int y; cin>>y;
  40.             if(!vis[y]){
  41.                 child.push_back(y);
  42.             }
  43.         }
  44.         if(child.size() == 0){
  45.             st.pop();
  46.             continue;
  47.         }
  48.         vis[child[0]] = true;
  49.         st.push(child[0]);
  50.     }
  51. }
  52.  
  53. int main(){
  54.     files();
  55.     int t = 1;
  56.     // cin>>t;
  57.     while(t--) solve();
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement