Submission #1105342

#TimeUsernameProblemLanguageResultExecution timeMemory
1105342ngokhanhHotspot (NOI17_hotspot)C++17
100 / 100
643 ms848 KiB
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i=a;i<=b;i++) #define rep2(i,a,b,c) for (int i=a;i<=b;i+=c) #define rev(i,a,b) for (int i=a;i>=b;i--) #define rev2(i,a,b,c) for (int i=a;i>=b;i-=c) #define ii pair<ll,ll> #define bit(i,j) ((i>>j)&1) #define ull unsigned long long #define pb push_back #define pf push_front #define ll long long #define F first #define S second #define sz(a) (int)(a.size()) #define on(n) __builtin_popcountll(n) #define ld long double #define __log2(x) 63-__builtin_clzll(x) #define Mask(x) (1LL<<x) #define ALL(v) v.begin(),v.end() const int N=5e3+5; const int mod=998244353; int n,m,k,u,v,a,b; int dist[N][2],cnt[N][2]; vector<int> g[N]; bool use[N]; ld ans[N]; void bfs(int s,int p){ rep(i,1,n){ use[i]=0; dist[s][p]=1e9; cnt[i][p]=0; } queue<int> q; q.push(s); use[s]=1; dist[s][p]=0; cnt[s][p]=1; while(!q.empty()){ int u=q.front(); q.pop(); for (int v:g[u]) if (!use[v]){ use[v]=1; dist[v][p]=dist[u][p]+1; cnt[v][p]=cnt[u][p]; q.push(v); } else if (dist[v][p]==dist[u][p]+1) cnt[v][p]+=cnt[u][p]; } } void solution(){ cin >> n >> m; rep(i,1,m){ cin >> u >> v; u++,v++; g[u].pb(v); g[v].pb(u); } cin >> k; rep(j,1,k){ cin >> a >> b; a++,b++; bfs(a,0); bfs(b,1); ld Y=cnt[b][0]*1.0; rep(i,1,n) if (dist[i][0]+dist[i][1]==dist[b][0]){ ld X=cnt[i][0]*cnt[i][1]*1.0; ans[i]=ans[i]*1.0+(X*1.0)/Y; } } int res=0; rep(i,1,n) if (ans[i]>ans[res]) res=i; cout << res-1; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test=1; //cin >> test; while(test--) solution(); }
#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...