답안 #37393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37393 2017-12-25T03:55:09 Z HardNut 관광지 (IZhO14_shymbulak) C++14
50 / 100
1500 ms 8412 KB
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;

const int N = 1e5 + 5;

typedef long long ll;

int n, ans, mx, d[N], ct[N];
vector<int> g[N];
bool used[N];

void bfs(int v) {
    queue<int> q;
    q.push(v);
    for (int i = 1; i <= n; i++) {
        used[i] = 0;
        ct[i] = 0;
    }
    d[v] = 0;
    used[v] = 1;
    ct[v] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int i = 0; i < g[u].size(); i++) {
            int to = g[u][i];
            if (!used[to]) {
                used[to] = 1;
                ct[to] = ct[u];
                d[to] = d[u] + 1;
                q.push(to);
            } else if (d[to] == d[u] + 1) {
                ct[to] += ct[u];
            }
        }
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        bfs(i);
        for (int j = 1; j <= n; j++) {
            if (d[j] > mx) {
                mx = d[j];
                ans = 0;
            }
            if (d[j] == mx) {
                ans += ct[j];
            }
        }
    }
    cout << ans / 2;
}

Compilation message

shymbulak.cpp: In function 'void bfs(int)':
shymbulak.cpp:30:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < g[u].size(); i++) {
                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5236 KB Output is correct
2 Correct 0 ms 5236 KB Output is correct
3 Correct 0 ms 5236 KB Output is correct
4 Correct 0 ms 5236 KB Output is correct
5 Correct 0 ms 5236 KB Output is correct
6 Correct 0 ms 5236 KB Output is correct
7 Correct 3 ms 5236 KB Output is correct
8 Correct 0 ms 5236 KB Output is correct
9 Correct 0 ms 5236 KB Output is correct
10 Correct 0 ms 5236 KB Output is correct
11 Correct 0 ms 5236 KB Output is correct
12 Correct 0 ms 5236 KB Output is correct
13 Correct 0 ms 5236 KB Output is correct
14 Correct 3 ms 5236 KB Output is correct
15 Correct 3 ms 5236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5236 KB Output is correct
2 Correct 9 ms 5236 KB Output is correct
3 Correct 16 ms 5236 KB Output is correct
4 Correct 16 ms 5236 KB Output is correct
5 Correct 606 ms 5368 KB Output is correct
6 Correct 469 ms 5500 KB Output is correct
7 Correct 673 ms 5368 KB Output is correct
8 Correct 706 ms 5368 KB Output is correct
9 Correct 646 ms 5368 KB Output is correct
10 Correct 699 ms 5368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1500 ms 8412 KB Execution timed out
2 Halted 0 ms 0 KB -