Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <unordered_set>
- using namespace std;
- #define st first
- #define nd second
- #define pb push_back
- #define mp make_pair
- #define klar(v) memset(v, 0, sizeof(v))
- #define bust ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define gcd(a, b) __gcd(a, b);
- #define debug cout << "chuj" << endl;
- #define endl "\n"
- typedef vector<int> vi;
- typedef vector<pair<int, int> > vpii;
- typedef vector<long long> vll;
- typedef pair<int, int> pii;
- typedef pair<long long, long long> pll;
- typedef long long ll;
- const int mamm = 3e3+200, maxn = 2e3+10, inf = 10000000;
- vi graph[3010];
- int odl[3010];
- bool done[3010];
- bool odw[3010];
- priority_queue <int> chuj;
- pii bfs(int v){
- queue <int> que;
- que.push(v);
- pii ret = mp(-1, -1);
- odw[v] = 1;
- while(que.size()){
- int v = que.front(); que.pop();
- // cout << v << " " << odl[v] << endl;
- if(odl[v] >= ret.st){
- ret.nd = max(ret.st, ret.nd);
- ret.st = odl[v];
- }
- for(auto i: graph[v]){
- if(odw[i] == true)continue;
- odw[i] = true;
- odl[i] = odl[v]+1;
- // cout << ">> " << i << "odl " << odl[i] << endl;
- que.push(i);
- }
- }
- return ret;
- }
- int main(){
- int n, m;
- scanf("%d%d", &n, &m);
- int it = mamm;
- vi prze;
- for(int i = 0; i < m; i++){
- int a, b;
- scanf("%d%d", &a, &b);
- graph[a].pb(b);
- graph[b].pb(a);
- it++;
- }
- // cout << bfs(1);
- int ans = 1e9;
- for(int i = 1; i <= n; i++){
- klar(odw);
- klar(odl);
- // cout << "check " << i << endl;
- pii h = bfs(i);
- // cout << "check " << i << " " << h.st << " " << h.nd << endl;
- ans = min(ans, h.st+h.nd);
- }
- // cout << ans << endl;
- printf("%d", ans/2);
- if((ans/2)*2 < ans)printf(".5");
- else printf(".0");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement