fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <iomanip>
  14. #define dibs reserve
  15. #define OVER9000 1234567890
  16. #define patkan 9
  17. #define tisic 47
  18. #define soclose 1e-9
  19. #define pi 3.1415926535898
  20. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  21. #define chocolate win
  22. #define ff first
  23. #define ss second
  24. #define abs(x) ((x < 0)?-(x):(x))
  25. #define uint unsigned int
  26. // mylittlepony
  27. using namespace std;
  28.  
  29. int N,M;
  30. vector< vector< pair<int,int> > > G;
  31.  
  32. bool bipar(int k) { // len prvych k (< k)
  33. vector<int> part(N,-1);
  34. queue<int> q;
  35. for(int i =0; i < N; i++) if(part[i] == -1) {
  36. q.push(i);
  37. part[i] =0;
  38. while(!q.empty()) {
  39. int a =q.front();
  40. ALL_THE(G[a],it) if(it->ss < k && part[it->ff] == -1) {
  41. part[it->ff] =1-part[a];
  42. q.push(it->ff);}
  43. q.pop();}
  44. }
  45. for(int i =0; i < N; i++) ALL_THE(G[i],it)
  46. if(part[i] == part[it->ff] && it->ss < k) return false;
  47. return true;}
  48.  
  49. int main() {
  50. cin.sync_with_stdio(0);
  51. cin >> N >> M;
  52. G.resize(N);
  53. for(int i =0; i < M; i++) {
  54. int a,b;
  55. cin >> a >> b;
  56. G[--a].push_back(make_pair(--b,i));
  57. G[b].push_back(make_pair(a,i));}
  58.  
  59. int a =0, b =M;
  60. while(b-a > 1) {
  61. int c =(b+a)/2;
  62. if(bipar(c)) a =c;
  63. else b =c;}
  64. cout << b << "\n";
  65. return 0;}
  66.  
  67. // look at my code
  68. // my code is amazing
  69.  
Success #stdin #stdout 0s 3436KB
stdin
Standard input is empty
stdout
0