Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Draw something someday
- But I don't know what to draw咩噗
- */
- using namespace std;
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <cmath>
- #include <utility>
- #include <bitset>
- #include <set>
- #include <string>
- #include <stack>
- #include <iomanip>
- #include <map>
- #define pb push_back
- #define pii pair<int,int>
- #define F first
- #define S second
- #define LL long long
- #define mid (LB+RB)/2
- #define iter(x) x.begin(),x.end()
- /*
- yungyao so weeeeeeeeeeeeeeeeeeeeeeeeeeak
- 8e7 so dian
- FHVirus so dian
- youou so dian
- KYW so dian
- hubert so dian
- jass so dian
- tingyu so dian
- panda so dian
- */
- //IO
- #include <iostream>
- #define theyRSOOOOOOOOODIAN ios_base::sync_with_stdio(false),cin.tie(0);
- #define endl '\n'
- //workspace
- bitset <100100> vis,color;
- vector <int> graph[100100];
- bool is_bipartite; //bipartite是二分的意思
- inline void init(int n){
- is_bipartite = true;
- vis.reset();
- color.reset();
- for (int i=1;i<=n;++i)
- graph[i].clear();
- }
- void dfs (int x,bool col){
- color[x] = col;
- vis[x] = true;
- for (auto i:graph[x]){
- if (vis[i]){
- if (col == color[i]){
- is_bipartite = false;
- return;
- }
- }
- else{
- dfs(i,!col);
- }
- }
- }
- inline void solve(int n,int m){
- init(n);
- while (m--){
- int u,v;
- cin >> u >> v;
- graph[u].pb(v);
- graph[v].pb(u);
- }
- for (int i=1;i<=n;++i){
- if (!vis[i])
- dfs(i,0);
- if (!is_bipartite)
- break;
- }
- cout << (is_bipartite ? "Yes\n" : "No\n");
- }
- int main(){
- theyRSOOOOOOOOODIAN
- for (int n,m;cin >> n >> m && (n || m);) solve(n,m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement