Submission #731824

#TimeUsernameProblemLanguageResultExecution timeMemory
731824TrunktyHotspot (NOI17_hotspot)C++14
100 / 100
1178 ms277648 KiB
#include <bits/extc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,m,q;
vector<int> roads[5005];
int best[5005][5005],cnt[5005][5005];
long double val[5005];

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        int a,b;
        cin >> a >> b;
        roads[a].push_back(b);
        roads[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            best[i][j] = 2000000000;
        }
        vector<int> v = {i};
        best[i][i] = 0;
        cnt[i][i] = 1;
        for(int j=0;j<v.size();j++){
            int x = v[j];
            for(int k:roads[x]){
                if(best[i][k]==best[i][x]+1){
                    cnt[i][k] += cnt[i][x];
                }
                else if(best[i][k]>best[i][x]+1){
                    best[i][k] = best[i][x]+1;
                    cnt[i][k] = cnt[i][x];
                    v.push_back(k);
                }
            }
        }
    }
    cin >> q;
    for(int i=1;i<=q;i++){
        int a,b;
        cin >> a >> b;
        for(int j=1;j<=n;j++){
            if(best[a][j]+best[b][j]==best[a][b]){
                long double p = cnt[a][j]*cnt[b][j];
                long double q = cnt[a][b];
                val[j] += p/q;
            }
        }
    }
    vector<pair<long double,int>> v;
    for(int i=1;i<=n;i++){
        v.push_back({val[i],i});
    }
    sort(v.begin(),v.end(),greater<pair<long double,int>>());
    cout << v[0].second << "\n";
	return 0;
}

Compilation message (stderr)

hotspot.cpp: In function 'int main()':
hotspot.cpp:28:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int j=0;j<v.size();j++){
      |                     ~^~~~~~~~~
#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...