Advertisement
Ahmed_Negm

Untitled

Apr 8th, 2024
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 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.     queue<int> q;
  21.     vis[s] = true;
  22.     int k; cin>>k;
  23.     for(int i = 0; i < k; i++){
  24.         int x; cin>>x;
  25.     }
  26.  
  27.     q.push(s);
  28.     vis[s] = true;
  29.  
  30.         while(!q.empty()){
  31.             int x = q.front();
  32.             q.pop();
  33.             cout<<"> "<<x<<endl;
  34.             cout.flush();
  35.             cin>>k;
  36.             if(k <= 0) return;
  37.             for(int i = 0; i < k; i++){
  38.                 int y; cin>>y;
  39.                 if(!vis[y]){
  40.                     vis[y] = true;
  41.                     q.push(y);
  42.                 }
  43.             }
  44.         }
  45.  
  46.  
  47.  
  48. }
  49.  
  50. int main(){
  51.     files();
  52.     int t = 1;
  53.     // cin>>t;
  54.     while(t--) solve();
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement