제출 #776569

#제출 시각아이디문제언어결과실행 시간메모리
776569CookieHotspot (NOI17_hotspot)C++14
100 / 100
643 ms25000 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("HAMMING.INP"); ofstream fout("HAMMING.OUT"); #define sz(a) (int)a.size() #define int long long #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; //const int x[4] = {1, -1, 0, 0}; const int y[4] = {0, 0, 1, -1}; const ll mod = 1e9 + 7,inf =1e18; const ll mxn = 1e6 + 5, sq = 500, mxv = 1e6 + 5; int n, m; vt<int>adj[mxn + 1]; ld ans[mxn + 1]; vt<pii>bfs(int s){ vt<pii>dis; dis.resize(n + 1); for(int i = 0; i < n; i++)dis[i].fi = 1e9; dis[s] = make_pair(0, 1); queue<int>q; q.push(s); while(!q.empty()){ int nw = q.front(); q.pop(); for(auto i: adj[nw]){ if(dis[i].fi > dis[nw].fi + 1){ dis[i].fi = dis[nw].fi + 1; dis[i].se = dis[nw].se; q.push(i); }else if(dis[i].fi == dis[nw].fi + 1){ dis[i].se += dis[nw].se; } } } return(dis); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; forr(i, 0, m){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } int k; cin >> k; while(k--){ int a, b; cin >> a >> b; vt<pii>d = bfs(a), d2 = bfs(b); for(int i = 0; i < n; i++){ if(d[i].fi + d2[i].fi == d[b].fi){ ans[i] += (ld)(d[i].se * d2[i].se) / (d[b].se); } } } ld mx = -1; int id = -1; for(int i = 0; i < n; i++){ if(ans[i] > mx){ mx = ans[i]; id = i; } } cout << id; return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...