Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <bitset>
- using namespace std;
- #define int long long
- #define inf (long long)1e18
- #define ll long long
- #define MOD 1000000007
- #define MOD1 998244353
- #define endl "\n"
- #define x first
- #define y second
- #define sz size()
- #ifndef ONLINE_JUDGE
- #include "debug.hpp"
- #define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
- #define fastio
- #else
- #define dbg(x...)
- #define fastio //ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- #endif
- #define all(x) (x).begin(), (x).end()
- #define NL cout<<endl;
- #define f(i, a, n) for (int i = a; i < n; i++)
- #define fr(i, n) for (int i = 0; i < n; i++)
- #define fr1(i, n) for(int i=1;i<=n;i++)
- #define frr(i,n) for(int i=n-1;i>=0;i--)
- #define each(x, a) for(auto &x : a)
- #define gcd(x, y) __gcd(x, y)
- #define lcm(x, y) ((x*y) / gcd(x, y))
- #define cl(a, b) ((a + b - 1)) /( b) //?ceill
- #define unq(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
- 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;}
- 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;}
- int modinv(int a,int m=MOD){return POWM(a,m-2,m);}
- #define sort_(a) sort(a.begin(),a.end())
- #define rev(a) reverse(a.begin(),a.end())
- #define ld long double
- #define prnt(a) cout << a << " ";
- 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;
- typedef priority_queue<int, vi> pq; // max heap
- typedef priority_queue<int, vi, greater<int>> mpq; // min heap
- #define pb push_back
- #define sum(a) accumulate(all(a),0LL)
- #define maxx(a) (*max_element(all(a)))
- #define minn(a) (*min_element(all(a)))
- #define no {cout<<"NO"<<endl; return;}
- #define yes {cout<<"YES"<<endl; return;}
- void in(vi &a,int n){a.resize(n);fr(i,n)cin>>a[i];}
- 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);}}
- 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);}};
- typedef unordered_map<int, int,custom_hash> unmap;
- typedef unordered_set<int, custom_hash> unset;
- 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}
- //* n & (n-1) removes the last set bit from LSB
- //* n & (-n) gives the last set bit from LSB
- //* n & (n+1) clears all trailing ONES
- //* n | (n+1) sets the last cleared bit 0011 0101 -> 0011 0111
- //* a+b=(a^b)+2(a&b) = (a|b) + (a&b)
- //__builtin_ffs //? returns the first bit set in a number
- //__has_single_bit(n) //? returns true if n is a power of 2
- // __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.
- // __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.
- // __builtin_popcountll(n) //? returns the number of 1-bits in n.
- // __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.
- // bit_ceil / bit_floor //?round up/down to the next power of two
- // if every you want to apply binary search and remove or add elements while doing bs in logn -> use multiset or set
- //* use ld not double
- //* don't use 1<<i else use power(2,i)
- void solve(int tc)
- {
- int n,m;
- cin>>n>>m;
- grf g;
- in(g,m);
- vi color(n,-1);
- qi q;
- q.push(0);
- color[0]=0;
- bool fg=1;
- while(q.sz)
- {
- int u=q.front();
- q.pop();
- each(v,g[u])
- {
- if(color[v]==-1)
- {
- color[v]=1-color[u];
- q.push(v);
- }
- if(color[v]==color[u])
- {
- fg=0;
- break;
- }
- }
- }
- si s1,s2;
- fr(i,n)
- {
- if(color[i]) s1.insert(i);
- else s2.insert(i);
- }
- if(fg==0) //not bipartite
- {
- cout<<"Alice"<<endl;
- cout.flush();
- fr(i,n)
- {
- cout<<"1 2"<<endl;
- cout.flush();
- int a,b;
- cin>>a>>b;
- cout.flush();
- }
- }
- else
- {
- cout<<"Bob"<<endl;
- cout.flush();
- cout<<endl;
- qi q;
- q.push(0);
- color.clear();
- vi vis(n,0);
- vis[0]=1;
- auto xx=[](int a)->pii
- {
- if(a==1) return {2,3};
- if(a==2) return {1,3};
- return {1,2};
- };
- // while(q.sz)
- // {
- // int u=q.front();
- // q.pop();
- // int a,b;
- // cin>>a>>b;
- // each(v,g[u])
- // {
- // if(vis[v]==-1)
- // {
- // q.push(v);
- // vis[v]=u;
- // }
- // }
- // if(color[vis[u]]==a)
- // color[u]=b;
- // else color[u]=a;
- // cout<<u+1<<" "<<a<<endl;
- // cout.flush();
- // }
- color.resize(n,-1);
- vii can(n);
- can[0]={1,2};
- fr(i,n)
- {
- int a,b;
- cin>>a>>b;
- if(a==-1 or b==-1) {assert(1<0); return ;}
- int u=q.front();
- q.pop();
- if(can[u].x==a) color[u]=a, cout<<u+1<<" "<<a<<endl;
- else if (can[u].y==a)color[u]=a, cout<<u+1<<" "<<a<<endl;
- else if(can[u].x==b)color[u]=b, cout<<u+1<<" "<<b<<endl;
- else if(can[u].y==b) color[u]=b,cout<<u+1<<" "<<b<<endl;
- else assert(1<0);
- cout.flush();
- cout<<endl;
- for(auto v:g[u])
- {
- if(vis[v]==0)
- {
- vis[v]=1;
- q.push(v);
- can[v]=xx(color[u]);
- }
- }
- }
- }
- }
- int32_t main()
- {
- fastio
- int t;
- cin>>t;
- // t=1;
- // ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- int tc=1;
- while (t--)
- {
- solve(tc),tc++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment