Guest User

Untitled

a guest
Jul 28th, 2024
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <bitset>
  3. using namespace std;
  4. #define int long long
  5. #define inf (long long)1e18
  6. #define ll long long
  7. #define MOD 1000000007
  8. #define MOD1 998244353
  9. #define endl "\n"
  10. #define x first
  11. #define y second
  12. #define sz size()
  13. #ifndef ONLINE_JUDGE
  14. #include "debug.hpp"
  15. #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
  16. #define fastio
  17. #else
  18. #define dbg(x...)
  19. #define fastio //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  20. #endif
  21. #define all(x) (x).begin(), (x).end()
  22. #define NL cout<<endl;
  23. #define f(i, a, n) for (int i = a; i < n; i++)
  24. #define fr(i, n) for (int i = 0; i < n; i++)
  25. #define fr1(i, n) for(int i=1;i<=n;i++)
  26. #define frr(i,n) for(int i=n-1;i>=0;i--)
  27. #define each(x, a) for(auto &x : a)
  28. #define gcd(x, y) __gcd(x, y)
  29. #define lcm(x, y) ((x*y) / gcd(x, y))
  30. #define cl(a, b) ((a + b - 1)) /( b) //?ceill
  31. #define unq(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
  32. int power(int a, int b){if(b==0)return 1;int res=power(a,b/2);if(b%2)return res*res*a;else return res*res;}
  33. int POWM(int a,int b,int m=MOD){a%=m;int res=1;while(b>0){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
  34. int modinv(int a,int m=MOD){return POWM(a,m-2,m);}
  35. #define sort_(a) sort(a.begin(),a.end())
  36. #define rev(a) reverse(a.begin(),a.end())
  37. #define ld long double
  38. #define prnt(a) cout << a << " ";
  39. typedef vector<ll>vi;typedef pair<ll,ll>pii;typedef vector<pii>vii;typedef vector<vi>vvi;typedef deque<int>dq;typedef map<int,int>mi;typedef map<pii,int>mii;typedef queue<int>qi;typedef queue<pii>qii;typedef map<int,vi>grf;typedef set<int>si;
  40. typedef priority_queue<int, vi> pq; // max heap
  41. typedef priority_queue<int, vi, greater<int>> mpq; // min heap
  42. #define pb push_back
  43. #define sum(a) accumulate(all(a),0LL)
  44. #define maxx(a) (*max_element(all(a)))
  45. #define minn(a) (*min_element(all(a)))
  46. #define no {cout<<"NO"<<endl; return;}
  47. #define yes {cout<<"YES"<<endl; return;}
  48. void in(vi &a,int n){a.resize(n);fr(i,n)cin>>a[i];}
  49. void in(grf &g, int m){int a,b;fr(i,m){cin>>a>>b,--a,--b,g[a].pb(b),g[b].pb(a);}}
  50. struct custom_hash{static uint64_t splitmix64(uint64_t x){x+=0x9e3779b97f4a7c15;x=(x^(x>>30))*0xbf58476d1ce4e5b9;x=(x^(x>>27))*0x94d049bb133111eb;return x^(x>>31);}size_t operator()(uint64_t x)const{static const uint64_t FIXED_RANDOM=chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x+FIXED_RANDOM);}};
  51. typedef unordered_map<int, int,custom_hash> unmap;
  52. typedef unordered_set<int, custom_hash> unset;
  53. void pt(vi &v){each(i,v)cout<<i<<" ";NL}void pt(int x){cout<<x;NL}void pt(string s){cout<<s;NL}void pt(char &c){cout<<c;NL}void pt(pii p){cout<<p.x<<" "<<p.y;NL}void pt(mi &mp){each(i,mp)cout<<i.x<<" "<<i.y;NL}void pt(unmap &mp){each(i,mp)cout<<i.x<<" "<<i.y;NL}void pt(vvi &v){each(i,v)pt(i);}void pt(vii &v){each(i,v)cout<<i.x<<" "<<i.y<<endl;}void pt(double &d){cout<<d;NL}void pt(float &f){cout<<f;NL}template<typename T>void pt(set<T>&s){each(i,s)cout<<i<<" ";NL}
  54. //* n & (n-1) removes the last set bit from LSB
  55. //* n & (-n) gives the last set bit from LSB
  56. //* n & (n+1)  clears all trailing ONES
  57. //* n | (n+1)  sets the last cleared bit 0011 0101 -> 0011 0111
  58. //* a+b=(a^b)+2(a&b) = (a|b) + (a&b)
  59. //__builtin_ffs //? returns the first bit set in a number
  60. //__has_single_bit(n) //? returns true if n is a power of 2
  61. // __builtin_clzll(n) //? returns the number of leading 0-bits in n, starting at the most significant bit position. If n is 0, the result is undefined.
  62. // __builtin_ctzll(n) //? returns the number of trailing 0-bits in n, starting at the least significant bit position. If n is 0, the result is undefined.
  63. // __builtin_popcountll(n) //? returns the number of 1-bits in n.
  64. // __builtin_parityll(n) //? returns the number of 1-bits in n modulo 2 =parity = Parity of a number refers to whether it contains an odd or even number of 1-bits.
  65. // bit_ceil / bit_floor //?round up/down to the next power of two
  66. // if every you want to apply binary search and remove or add elements while doing bs in logn -> use multiset or set
  67. //* use ld not double
  68. //* don't use 1<<i else use power(2,i)
  69.  
  70. void solve(int tc)
  71. {
  72.     int n,m;
  73.     cin>>n>>m;
  74.     grf g;
  75.     in(g,m);
  76.     vi color(n,-1);
  77.     qi q;
  78.     q.push(0);
  79.     color[0]=0;
  80.     bool fg=1;
  81.     while(q.sz)
  82.     {
  83.         int u=q.front();
  84.         q.pop();
  85.         each(v,g[u])
  86.         {
  87.             if(color[v]==-1)
  88.             {
  89.                 color[v]=1-color[u];
  90.                 q.push(v);
  91.             }
  92.             if(color[v]==color[u])
  93.             {
  94.                 fg=0;
  95.                 break;
  96.             }
  97.         }
  98.     }
  99.     si s1,s2;
  100.     fr(i,n)
  101.     {
  102.         if(color[i]) s1.insert(i);
  103.         else s2.insert(i);
  104.     }
  105.     if(fg==0) //not bipartite
  106.     {
  107.         cout<<"Alice"<<endl;
  108.         cout.flush();
  109.         fr(i,n)
  110.         {
  111.             cout<<"1 2"<<endl;
  112.             cout.flush();
  113.             int a,b;
  114.             cin>>a>>b;
  115.             cout.flush();
  116.         }
  117.     }
  118.     else
  119.     {
  120.         cout<<"Bob"<<endl;
  121.         cout.flush();
  122.         cout<<endl;
  123.         qi q;
  124.         q.push(0);
  125.         color.clear();
  126.         vi vis(n,0);
  127.         vis[0]=1;
  128.         auto xx=[](int a)->pii
  129.         {
  130.             if(a==1) return {2,3};
  131.             if(a==2) return {1,3};
  132.              return {1,2};
  133.         };
  134.         // while(q.sz)
  135.         // {
  136.         //     int u=q.front();
  137.         //     q.pop();
  138.         //     int a,b;
  139.         //     cin>>a>>b;
  140.         //     each(v,g[u])
  141.         //     {
  142.         //         if(vis[v]==-1)
  143.         //         {
  144.         //             q.push(v);
  145.         //             vis[v]=u;
  146.         //         }
  147.         //     }
  148.         //     if(color[vis[u]]==a)
  149.         //         color[u]=b;
  150.         //     else color[u]=a;
  151.         //     cout<<u+1<<" "<<a<<endl;
  152.         //     cout.flush();
  153.         // }      
  154.         color.resize(n,-1);
  155.         vii can(n);
  156.         can[0]={1,2};
  157.         fr(i,n)
  158.         {
  159.             int a,b;
  160.             cin>>a>>b;
  161.             if(a==-1 or b==-1) {assert(1<0); return ;}
  162.             int u=q.front();
  163.             q.pop();
  164.             if(can[u].x==a) color[u]=a, cout<<u+1<<" "<<a<<endl;
  165.             else if (can[u].y==a)color[u]=a, cout<<u+1<<" "<<a<<endl;
  166.             else if(can[u].x==b)color[u]=b, cout<<u+1<<" "<<b<<endl;
  167.             else if(can[u].y==b) color[u]=b,cout<<u+1<<" "<<b<<endl;
  168.             else assert(1<0);
  169.             cout.flush();
  170.             cout<<endl;
  171.             for(auto v:g[u])
  172.             {
  173.                 if(vis[v]==0)
  174.                 {
  175.                     vis[v]=1;
  176.                     q.push(v);
  177.                     can[v]=xx(color[u]);
  178.                 }
  179.             }
  180.            
  181.         }
  182.  
  183.     }
  184. }  
  185. int32_t main()      
  186. {  
  187.     fastio
  188.     int t;
  189.     cin>>t;
  190.     // t=1;
  191.     // ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  192.     int tc=1;
  193.     while (t--)
  194.     {
  195.         solve(tc),tc++;
  196.     }
  197.     return 0;
  198. }  
Advertisement
Add Comment
Please, Sign In to add comment