Submission #1105401

# Submission time Handle Problem Language Result Execution time Memory
1105401 2024-10-26T09:37:54 Z HNa_seawjing Hotspot (NOI17_hotspot) C++14
100 / 100
1258 ms 363004 KB
#include <bits/stdc++.h>
//code
#define fl(i,x,y,z) for(int i=x;i<=y;i=i+z)
#define fn(i,x,y,z) for(int i=x;i>=y;i=i-z)
#define rep(i,x,y) for(int i=x;i<y;i=i+1)
#define all(v) v.begin(),v.end()
#define pb emplace_back
#define tle cout<<"tle"<<endl
#define edl cout<<"\n"
#define el "\n"
#define getbit(x,i) ((x>>i)&1)
#define bitcnt __builtin_popcount
//ham
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
//#define int long long
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int maxn=1e6+5;
int n,m,k,d[5001][5001],ans_node,x[2001],y[2001];
vector<int> adj[5001];
queue<int> q;
long double ans,cnt[5001][5001];

void bfs(int x)
{
    memset(d[x],0x3f,sizeof(d[x]));
    q.push(x);
    d[x][x]=0;
    cnt[x][x]=1;

    while (!q.empty())
    {
        int a=q.front();
        q.pop();
        for (auto s : adj[a])
        {
            if (d[x][s]>d[x][a]+1)
            {
                d[x][s]=d[x][a]+1;
                cnt[x][s]+=cnt[x][a];
                q.push(s);
            }
            else if (d[x][s]==d[x][a]+1) cnt[x][s]+=cnt[x][a];
        }
    }
}
void inp()
{
    cin>>n>>m;
    for (int i=0; i<m; ++i)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin>>k;
    for (int i=0; i<k; ++i) cin>>x[i]>>y[i];
}
void sol()
{
    for (int i=0; i<n; ++i) bfs(i);
    for (int i=0; i<n; ++i)
    {
        long double sum=0;
        for (int j=0; j<k; ++j)
        {
            if (d[x[j]][i]+d[i][y[j]]==d[x[j]][y[j]])
                sum+=(cnt[x[j]][i]*cnt[i][y[j]])/cnt[x[j]][y[j]];
        }
        if (sum>ans) ans_node=i,ans=sum;
    }
    cout<<ans_node;
}
signed main()
{
#define name "seaw"
    if (fopen(name".inp", "r"))
    {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    inp();
    sol();
    return 0;
}
/*   /\_/\
    ( ._. )
    / >V< \
*/

Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 53840 KB Output is correct
2 Correct 15 ms 80976 KB Output is correct
3 Correct 14 ms 74576 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 5 ms 33104 KB Output is correct
6 Correct 5 ms 29008 KB Output is correct
7 Correct 9 ms 55888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 53840 KB Output is correct
2 Correct 15 ms 80976 KB Output is correct
3 Correct 14 ms 74576 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 5 ms 33104 KB Output is correct
6 Correct 5 ms 29008 KB Output is correct
7 Correct 9 ms 55888 KB Output is correct
8 Correct 5 ms 29008 KB Output is correct
9 Correct 9 ms 55904 KB Output is correct
10 Correct 16 ms 83028 KB Output is correct
11 Correct 2 ms 12624 KB Output is correct
12 Correct 1 ms 8528 KB Output is correct
13 Correct 6 ms 35152 KB Output is correct
14 Correct 12 ms 62288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 53840 KB Output is correct
2 Correct 15 ms 80976 KB Output is correct
3 Correct 14 ms 74576 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 5 ms 33104 KB Output is correct
6 Correct 5 ms 29008 KB Output is correct
7 Correct 9 ms 55888 KB Output is correct
8 Correct 5 ms 35152 KB Output is correct
9 Correct 12 ms 62288 KB Output is correct
10 Correct 10 ms 57936 KB Output is correct
11 Correct 17 ms 83024 KB Output is correct
12 Correct 3 ms 14672 KB Output is correct
13 Correct 2 ms 8528 KB Output is correct
14 Correct 6 ms 37560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 53840 KB Output is correct
2 Correct 15 ms 80976 KB Output is correct
3 Correct 14 ms 74576 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 5 ms 33104 KB Output is correct
6 Correct 5 ms 29008 KB Output is correct
7 Correct 9 ms 55888 KB Output is correct
8 Correct 5 ms 29008 KB Output is correct
9 Correct 9 ms 55904 KB Output is correct
10 Correct 16 ms 83028 KB Output is correct
11 Correct 2 ms 12624 KB Output is correct
12 Correct 1 ms 8528 KB Output is correct
13 Correct 6 ms 35152 KB Output is correct
14 Correct 12 ms 62288 KB Output is correct
15 Correct 5 ms 35152 KB Output is correct
16 Correct 12 ms 62288 KB Output is correct
17 Correct 10 ms 57936 KB Output is correct
18 Correct 17 ms 83024 KB Output is correct
19 Correct 3 ms 14672 KB Output is correct
20 Correct 2 ms 8528 KB Output is correct
21 Correct 6 ms 37560 KB Output is correct
22 Correct 8 ms 43600 KB Output is correct
23 Correct 7 ms 39248 KB Output is correct
24 Correct 13 ms 64348 KB Output is correct
25 Correct 24 ms 89672 KB Output is correct
26 Correct 20 ms 83552 KB Output is correct
27 Correct 3 ms 18768 KB Output is correct
28 Correct 9 ms 45648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 53840 KB Output is correct
2 Correct 15 ms 80976 KB Output is correct
3 Correct 14 ms 74576 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 5 ms 33104 KB Output is correct
6 Correct 5 ms 29008 KB Output is correct
7 Correct 9 ms 55888 KB Output is correct
8 Correct 5 ms 29008 KB Output is correct
9 Correct 9 ms 55904 KB Output is correct
10 Correct 16 ms 83028 KB Output is correct
11 Correct 2 ms 12624 KB Output is correct
12 Correct 1 ms 8528 KB Output is correct
13 Correct 6 ms 35152 KB Output is correct
14 Correct 12 ms 62288 KB Output is correct
15 Correct 13 ms 19024 KB Output is correct
16 Correct 20 ms 45648 KB Output is correct
17 Correct 57 ms 72764 KB Output is correct
18 Correct 31 ms 64516 KB Output is correct
19 Correct 73 ms 91784 KB Output is correct
20 Correct 11 ms 25168 KB Output is correct
21 Correct 5 ms 18768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 53840 KB Output is correct
2 Correct 15 ms 80976 KB Output is correct
3 Correct 14 ms 74576 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 5 ms 33104 KB Output is correct
6 Correct 5 ms 29008 KB Output is correct
7 Correct 9 ms 55888 KB Output is correct
8 Correct 5 ms 29008 KB Output is correct
9 Correct 9 ms 55904 KB Output is correct
10 Correct 16 ms 83028 KB Output is correct
11 Correct 2 ms 12624 KB Output is correct
12 Correct 1 ms 8528 KB Output is correct
13 Correct 6 ms 35152 KB Output is correct
14 Correct 12 ms 62288 KB Output is correct
15 Correct 5 ms 35152 KB Output is correct
16 Correct 12 ms 62288 KB Output is correct
17 Correct 10 ms 57936 KB Output is correct
18 Correct 17 ms 83024 KB Output is correct
19 Correct 3 ms 14672 KB Output is correct
20 Correct 2 ms 8528 KB Output is correct
21 Correct 6 ms 37560 KB Output is correct
22 Correct 8 ms 43600 KB Output is correct
23 Correct 7 ms 39248 KB Output is correct
24 Correct 13 ms 64348 KB Output is correct
25 Correct 24 ms 89672 KB Output is correct
26 Correct 20 ms 83552 KB Output is correct
27 Correct 3 ms 18768 KB Output is correct
28 Correct 9 ms 45648 KB Output is correct
29 Correct 13 ms 19024 KB Output is correct
30 Correct 20 ms 45648 KB Output is correct
31 Correct 57 ms 72764 KB Output is correct
32 Correct 31 ms 64516 KB Output is correct
33 Correct 73 ms 91784 KB Output is correct
34 Correct 11 ms 25168 KB Output is correct
35 Correct 5 ms 18768 KB Output is correct
36 Correct 31 ms 25180 KB Output is correct
37 Correct 141 ms 111956 KB Output is correct
38 Correct 1218 ms 310600 KB Output is correct
39 Correct 123 ms 73064 KB Output is correct
40 Correct 503 ms 255560 KB Output is correct
41 Correct 1258 ms 363004 KB Output is correct
42 Correct 281 ms 118856 KB Output is correct
43 Correct 184 ms 182800 KB Output is correct
44 Correct 175 ms 182856 KB Output is correct