답안 #210003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210003 2020-03-16T08:42:00 Z Alexa2001 Hotspot (NOI17_hotspot) C++17
100 / 100
666 ms 61816 KB
#include <bits/stdc++.h>

using namespace std;

///10:23

const int Nmax = 5005;

long double ans[Nmax];
bool used[Nmax];
vector<int> v[Nmax];

int dist[Nmax][Nmax], pos[Nmax][Nmax], A[Nmax], B[Nmax];
int n, m, k;

void doo(int node, int dist[], int pos[])
{
    int i;
    for(i=0; i<n; ++i) dist[i] = -1;

    dist[node] = 0;
    pos[node] = 1;

    queue<int> q;
    q.push(node);

    while(q.size())
    {
        node = q.front();
        q.pop();

        for(auto it : v[node])
            if(dist[it] == -1)
            {
                dist[it] = dist[node] + 1;
                pos[it] = pos[node];
                q.push(it);
            }
            else if(dist[it] == dist[node] + 1)
                pos[it] += pos[node];
    }
}

int main()
{
   // freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;

    int i, j;
    for(i=1; i<=m; ++i)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    cin >> k;
    for(i=1; i<=k; ++i)
    {
        cin >> A[i] >> B[i];
        if(!used[A[i]]) doo(A[i], dist[A[i]], pos[A[i]]), used[A[i]] = 1;
        if(!used[B[i]]) doo(B[i], dist[B[i]], pos[B[i]]), used[B[i]] = 1;
    }

    for(i=1; i<=k; ++i)
        for(j=0; j<n; ++j)
            if(dist[A[i]][j] + dist[B[i]][j] == dist[A[i]][B[i]])
                ans[j] += (long double) pos[A[i]][j] * pos[B[i]][j] / pos[A[i]][B[i]];

    int id = 0;
    for(i=0; i<n; ++i)
        if(ans[i] > ans[id])
            id = i;
    cout << id << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 6 ms 1272 KB Output is correct
9 Correct 6 ms 1656 KB Output is correct
10 Correct 7 ms 1784 KB Output is correct
11 Correct 9 ms 2552 KB Output is correct
12 Correct 5 ms 1272 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 7 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 6 ms 1272 KB Output is correct
16 Correct 6 ms 1656 KB Output is correct
17 Correct 7 ms 1784 KB Output is correct
18 Correct 9 ms 2552 KB Output is correct
19 Correct 5 ms 1272 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 7 ms 2680 KB Output is correct
22 Correct 6 ms 1400 KB Output is correct
23 Correct 6 ms 1528 KB Output is correct
24 Correct 7 ms 2040 KB Output is correct
25 Correct 9 ms 2808 KB Output is correct
26 Correct 9 ms 2808 KB Output is correct
27 Correct 6 ms 1656 KB Output is correct
28 Correct 8 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 6 ms 632 KB Output is correct
17 Correct 10 ms 1144 KB Output is correct
18 Correct 7 ms 1016 KB Output is correct
19 Correct 9 ms 1148 KB Output is correct
20 Correct 7 ms 760 KB Output is correct
21 Correct 5 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 6 ms 1272 KB Output is correct
16 Correct 6 ms 1656 KB Output is correct
17 Correct 7 ms 1784 KB Output is correct
18 Correct 9 ms 2552 KB Output is correct
19 Correct 5 ms 1272 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 7 ms 2680 KB Output is correct
22 Correct 6 ms 1400 KB Output is correct
23 Correct 6 ms 1528 KB Output is correct
24 Correct 7 ms 2040 KB Output is correct
25 Correct 9 ms 2808 KB Output is correct
26 Correct 9 ms 2808 KB Output is correct
27 Correct 6 ms 1656 KB Output is correct
28 Correct 8 ms 3064 KB Output is correct
29 Correct 6 ms 632 KB Output is correct
30 Correct 6 ms 632 KB Output is correct
31 Correct 10 ms 1144 KB Output is correct
32 Correct 7 ms 1016 KB Output is correct
33 Correct 9 ms 1148 KB Output is correct
34 Correct 7 ms 760 KB Output is correct
35 Correct 5 ms 632 KB Output is correct
36 Correct 32 ms 2680 KB Output is correct
37 Correct 113 ms 14556 KB Output is correct
38 Correct 666 ms 61816 KB Output is correct
39 Correct 148 ms 11128 KB Output is correct
40 Correct 93 ms 15992 KB Output is correct
41 Correct 455 ms 51332 KB Output is correct
42 Correct 282 ms 21752 KB Output is correct
43 Correct 46 ms 8568 KB Output is correct
44 Correct 41 ms 7776 KB Output is correct