Advertisement
TheAnshul

Tree input Generator

Aug 28th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. /***** TheAnshul *****/
  2.  
  3. #include<bits/stdc++.h>
  4. #define ll          long long
  5. #define pb          push_back
  6. #define ppb         pop_back
  7. #define endl        '\n'
  8. #define mii         map<ll int,ll int>
  9. #define msi         map<string,ll int>
  10. #define mis         map<ll int, string>
  11. #define rep(i,a,b)    for(ll int i=a;i<b;i++)
  12. #define mpi         map<pair<ll int,ll int>,ll int>
  13. #define pii         pair<ll int,ll int>
  14. #define vi          vector<ll int>
  15. #define vii         vector<pair<ll int, ll int>>
  16. #define vs          vector<string>
  17. #define all(a)      (a).begin(),(a).end()
  18. #define F           first
  19. #define S           second
  20. #define sz(x)       (ll int)x.size()
  21. #define hell        1000000007
  22. #define lbnd        lower_bound
  23. #define ubnd        upper_bound
  24. #define bs          binary_search
  25. #define mp          make_pair
  26. #define what_is(x)  cerr << #x << " is " << x << endl;
  27. using namespace std;
  28. #define N  200000          // to generate n change vale of N here.
  29. ll n=N;
  30. // ll n=rand()%(N-1)+1;
  31. bool vis[N+5];
  32. ll last=2;
  33. vi a[N+5];
  34. void dfs(ll node)
  35. {
  36.     vis[node]=1;
  37.     int ch=rand()%10+1;
  38.     rep(i,0,ch)
  39.     {
  40.         a[node].pb(last);
  41.         a[last].pb(node);
  42.         cout<<last<<" "<<node<<endl;
  43.         last++;
  44.         if(last==n+1)
  45.             exit(0);
  46.     }
  47.     for(auto i:a[node])
  48.     if(!vis[i])
  49.     dfs(i);
  50. }
  51. int main()
  52. {
  53.     ios_base::sync_with_stdio(false);
  54.     cin.tie(0);
  55.     cout.tie(0);
  56.     int TESTS=1;
  57. //  cin>>TESTS;
  58.             /************************************/
  59.             // freopen("input.txt","r",stdin);
  60.             freopen("input.txt","w",stdout);
  61.             /***********************************/
  62.     while(TESTS--)
  63.     {
  64.         cout<<n<<endl;
  65.         dfs(1);
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement