Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <unordered_set>
  3. using namespace std;
  4.  
  5. #define st first
  6. #define nd second
  7. #define pb push_back
  8. #define mp make_pair
  9. #define klar(v) memset(v, 0, sizeof(v))
  10. #define bust ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  11. #define gcd(a, b) __gcd(a, b);
  12. #define debug cout << "chuj" << endl;
  13. #define endl "\n"
  14.  
  15. typedef vector<int> vi;
  16. typedef vector<pair<int, int> > vpii;
  17. typedef vector<long long> vll;
  18. typedef pair<int, int> pii;
  19. typedef pair<long long, long long> pll;
  20. typedef long long ll;
  21. const int mamm = 3e3+200, maxn = 2e3+10, inf = 10000000;
  22.  
  23. vi graph[3010];
  24. int odl[3010];
  25. bool done[3010];
  26. bool odw[3010];
  27. priority_queue <int> chuj;
  28. pii bfs(int v){
  29.     queue <int> que;
  30.     que.push(v);
  31.     pii ret = mp(-1, -1);
  32.     odw[v] = 1;
  33.     while(que.size()){
  34.         int v = que.front(); que.pop();
  35. //        cout << v << " " << odl[v] << endl;
  36.         if(odl[v] >= ret.st){
  37.             ret.nd = max(ret.st, ret.nd);
  38.             ret.st = odl[v];
  39.         }
  40.        
  41.         for(auto i: graph[v]){
  42.             if(odw[i] == true)continue;
  43.             odw[i] = true;
  44.             odl[i] = odl[v]+1;
  45. //            cout << ">> " << i << "odl " << odl[i] << endl;
  46.             que.push(i);
  47.         }
  48.     }
  49.     return ret;
  50. }
  51.  
  52. int main(){
  53.     int n, m;
  54.     scanf("%d%d", &n, &m);
  55.     int it = mamm;
  56.     vi prze;
  57.     for(int i = 0; i < m; i++){
  58.         int a, b;
  59.         scanf("%d%d", &a, &b);
  60.         graph[a].pb(b);
  61.         graph[b].pb(a);
  62.         it++;
  63.     }
  64. //        cout << bfs(1);
  65.     int ans = 1e9;
  66.     for(int i = 1; i <= n; i++){
  67.         klar(odw);
  68.         klar(odl);
  69. //        cout << "check " << i << endl;
  70.         pii h = bfs(i);
  71. //        cout << "check " << i << " " << h.st << " " << h.nd << endl;
  72.         ans = min(ans, h.st+h.nd);
  73.     }
  74. //    cout << ans << endl;
  75.     printf("%d", ans/2);
  76.     if((ans/2)*2 < ans)printf(".5");
  77.     else printf(".0");
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement