Advertisement
yungyao

tioj 1209

Apr 1st, 2021
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /*
  2.  
  3.  
  4.  
  5.  
  6.                 Draw something someday
  7.                 But I don't know what to draw咩噗
  8.  
  9.  
  10.  
  11.  
  12. */
  13. using namespace std;
  14. #include <vector>
  15. #include <queue>
  16. #include <algorithm>
  17. #include <cmath>
  18. #include <utility>
  19. #include <bitset>
  20. #include <set>
  21. #include <string>
  22. #include <stack>
  23. #include <iomanip>
  24. #include <map>
  25.  
  26. #define pb push_back
  27. #define pii pair<int,int>
  28. #define F first
  29. #define S second
  30. #define LL long long
  31. #define mid (LB+RB)/2
  32. #define iter(x) x.begin(),x.end()
  33.  
  34. /*
  35. yungyao so weeeeeeeeeeeeeeeeeeeeeeeeeeak
  36. 8e7 so dian
  37. FHVirus so dian
  38. youou so dian
  39. KYW so dian
  40. hubert so dian
  41. jass so dian
  42. tingyu so dian
  43. panda so dian
  44. */
  45.  
  46. //IO
  47. #include <iostream>
  48. #define theyRSOOOOOOOOODIAN ios_base::sync_with_stdio(false),cin.tie(0);
  49. #define endl '\n'
  50.  
  51. //workspace
  52.  
  53. bitset <100100> vis,color;
  54. vector <int> graph[100100];
  55. bool is_bipartite; //bipartite是二分的意思
  56.  
  57. inline void init(int n){
  58.     is_bipartite = true;
  59.     vis.reset();
  60.     color.reset();
  61.     for (int i=1;i<=n;++i)
  62.         graph[i].clear();
  63. }
  64.  
  65. void dfs (int x,bool col){
  66.     color[x] = col;
  67.     vis[x] = true;
  68.  
  69.     for (auto i:graph[x]){
  70.         if (vis[i]){
  71.             if (col == color[i]){
  72.                 is_bipartite = false;
  73.                 return;
  74.             }
  75.         }
  76.         else{
  77.             dfs(i,!col);
  78.         }
  79.     }
  80. }
  81.  
  82. inline void solve(int n,int m){
  83.     init(n);
  84.  
  85.     while (m--){
  86.         int u,v;
  87.  
  88.         cin >> u >> v;
  89.         graph[u].pb(v);
  90.         graph[v].pb(u);
  91.     }
  92.  
  93.     for (int i=1;i<=n;++i){
  94.         if (!vis[i])
  95.             dfs(i,0);
  96.        
  97.         if (!is_bipartite)
  98.             break;
  99.     }
  100.  
  101.     cout << (is_bipartite ? "Yes\n" : "No\n");
  102. }
  103.  
  104. int main(){
  105.     theyRSOOOOOOOOODIAN
  106.     for (int n,m;cin >> n >> m && (n || m);) solve(n,m);
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement