Submission #1234047

#TimeUsernameProblemLanguageResultExecution timeMemory
1234047GeforgsHotspot (NOI17_hotspot)C++20
38 / 100
3 ms584 KiB
#include <iostream> #include <iomanip> #include <vector> #include <cmath> #include <algorithm> #include <set> #include <queue> #include <map> #include <unordered_map> #include <stack> #include <bitset> #include <string> #include <cstring> #include <iterator> #include <random> #define ll long long #define ld long double #define inf (ll)(2*1e18) #define sort(a) sort(a.begin(), a.end()) #define reverse(a) reverse(a.begin(), a.end()) #define pb push_back #define endl "\n" using namespace std; ll gcd(ll a, ll b){ if(a == 0) return b; return gcd(b%a, a); } struct fraction{ ll x=0, y=1; bool operator>(fraction& another){ return x*another.y > y*another.x; } void div(){ ll g = gcd(x, y); x /= g; y /= g; } }; void find(ll n, ll x, ll y, vector<vector<ll>>& a, vector<fraction>& ans){ vector<ll> dis1(n, -1); vector<ll> dis2(n, -1); vector<ll> cnt1(n, 0); vector<ll> cnt2(n, 0); queue<ll> que; dis1[x] = 0; cnt1[x] = 1; que.push(x); while(!que.empty()){ auto z = que.front(); que.pop(); for(auto el: a[z]){ if(dis1[el] == -1){ dis1[el] = dis1[z] + 1; que.push(el); } if(dis1[el] == dis1[z] + 1){ cnt1[el] += cnt1[z]; } } } dis2[y] = 0; cnt2[y] = 1; que.push(y); while(!que.empty()){ auto z = que.front(); que.pop(); for(auto el: a[z]){ if(dis2[el] == -1){ dis2[el] = dis2[z] + 1; que.push(el); } if(dis2[el] == dis2[z] + 1){ cnt2[el] += cnt2[z]; } } } ll dis = dis1[y], cnt=cnt1[y], b, c, g; for(int i=0;i<n;++i){ if(dis1[i] + dis2[i] == dis){ b = (cnt1[i] + cnt2[i]); c = cnt; g = gcd(b, c); b /= g; c /= g; ans[i].x *= c; ans[i].x += b*ans[i].y; ans[i].y *= c; ans[i].div(); } } } void solve(){ ll n, m, k, i, x, y, answer=0; fraction res; cin>>n>>m; vector<vector<ll>> a(n); vector<fraction> ans(n); for(i=0;i<m;++i){ cin>>x>>y; a[x].pb(y); a[y].pb(x); } cin>>k; for(i=0;i<k;++i){ cin>>x>>y; find(n, x, y, a, ans); } for(i=0;i<n;++i){ if(ans[i] > res){ res = ans[i]; answer = i; } } cout<<answer<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); srand(time(nullptr)); ll t=1; // cin>>t; for(;t>0;--t){ solve(); } 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...