Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb(x) push_back(x);
- #define in(y) insert(y);
- #define tt(t) while(t--)
- #define itr ::iterator it;
- #define ll long long
- #define vi vector<int>
- #define ii pair<int, int>
- #define vii vector<ii>
- #define si set<int>
- #define msi map<string, int>
- #define new cout<<endl
- #define ff(n) for(int i=0;i<n;i++)
- #define all(v) sort(v.begin(),v.end())
- using namespace std;
- int V=0,m,n;
- int colorArr[1024];
- bool isBP(int G[][1024], int src)
- {
- for (int i = 0; i < V; ++i)
- colorArr[i] = -1;
- colorArr[src] = 1;
- queue <int> q;
- q.push(src);
- while (!q.empty())
- {
- int u = q.front();
- q.pop();
- for (int v = 0; v < V; ++v)
- {
- if (G[u][v] && colorArr[v] == -1)
- {
- // Assign alternate color to this adjacent v of u
- colorArr[v] = 1 - colorArr[u];
- q.push(v);
- }
- else if (G[u][v] && colorArr[v] == colorArr[u])
- return false;
- }
- }
- return true;
- }
- int mat[1024][1024];
- int main(){
- int t;
- cin>>t;
- while(t--){
- cin>>n>>m;
- for(int i=0;i<V;i++)
- for(int j=0;j<V;j++)
- mat[i][j]=1;
- int fr,to;
- while(m--) {
- cin>>fr>>to;
- mat[fr-1][to-1]=0;
- }
- if(isBP(mat,0)) cout<<"Yes\n";
- else cout<<"No\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment