답안 #1102922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102922 2024-10-19T08:51:47 Z Avocabo Hotspot (NOI17_hotspot) C++17
9 / 100
5 ms 6480 KB
#include <bits/stdc++.h>
using namespace std;

#define task "TRAINCENTER"
#define fi first
#define se second
#define pii pair <int, int>
#define pb push_back
#define ll long long 
#define pip pair <int, pii>
#define pli pair <ll, int>

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;

int myabs(int x)
{
    return x < 0 ? -x : x;
}

int n, m, k;
vector <int> g[N];
long long cnt[2][N], d[2][N];
double ans[N];

void inp()
{
    cin >> n >> m;
    for (int i=1; i<=m; ++i)
    {
        int u, v;
        cin >> u >> v;
        u++;
        v++;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    cin >> k;
}

void bfs(int id, int s)
{
    queue <int> q;
    for (int i=0; i<=n; ++i)
        d[id][i] = -1,
        cnt[id][i] = 0;
    d[id][s] = 0;
    q.push(s);
    cnt[id][s] = 1;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int v : g[u])
        {
            if (d[id][v] == -1)
            {
                d[id][v] = d[id][u] + 1;
                cnt[id][v] = cnt[id][u];
                q.push(v);
            }
            else if (d[id][v] == d[id][u] + 1)
                cnt[id][v] += cnt[id][u];
        }
    }
}

void solve()
{
    while (k--)
    {
        int a, b;
        cin >> a >> b;
        a++;
        b++;
        bfs(0, a);
        bfs(1, b);
        double tmp = cnt[0][b];
        for (int i=1; i<=n; ++i)
            if (d[0][i] + d[1][i] == d[0][b])
            {
                double tmp1 = (double)(cnt[0][i] * cnt[1][i]);
                ans[i] += (tmp1/tmp);
            }
    }
    int res = 0;
    for (int i=1; i<=n; ++i)
        if (ans[i] > ans[res])
            res = i-1;
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    inp();
    solve();
    return 0;
}



Compilation message

hotspot.cpp: In function 'int main()':
hotspot.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6324 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 4 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6324 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 4 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6324 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 4 ms 6480 KB Output is correct
8 Incorrect 3 ms 6480 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6324 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 4 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6480 KB Output is correct
15 Incorrect 3 ms 6480 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6324 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 4 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6480 KB Output is correct
15 Correct 5 ms 6480 KB Output is correct
16 Incorrect 3 ms 6480 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6324 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Correct 4 ms 6480 KB Output is correct
8 Correct 2 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 3 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 2 ms 6480 KB Output is correct
14 Correct 3 ms 6480 KB Output is correct
15 Incorrect 3 ms 6480 KB Output isn't correct
16 Halted 0 ms 0 KB -