답안 #337279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337279 2020-12-19T08:28:35 Z boykut 관광지 (IZhO14_shymbulak) C++14
50 / 100
605 ms 876 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5005;
const int INF = 2'000'000'000;

int n;
vector<int> g[MAXN];

int cur = 0, cnt = 0;

void bfs(int a) {
   int dist[MAXN];
   fill (dist, dist + MAXN, INF);
   
   queue < int > q;
   q.push(a);
   dist[a] = 0;
   
   while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto i : g[v]) {
         if (dist[i] >= dist[v] + 1) {
            q.push(i);
            dist[i] = dist[v] + 1;
            if (dist[i] == cur) {
               cnt++;
            } else if (dist[i] > cur) {
               cur = dist[i];
               cnt = 1;
            }
         }
      }
   }
   return;
}

signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   
   cin >> n;
   for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      g[a].push_back(b);
      g[b].push_back(a);
   }
   
   int ansD = 0, cntWay = 0;
   for (int i = 1; i <= n; i++) {
      cur = 0;
      cnt = 0;
      bfs(i);
      if (cur == ansD) {
         cntWay += cnt;
      } else if (cur > ansD) {
         ansD = cur;
         cntWay = cnt;
      }
   }
   
   cout << cntWay / 2 << endl;
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 7 ms 492 KB Output is correct
15 Correct 7 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 492 KB Output is correct
2 Correct 10 ms 512 KB Output is correct
3 Correct 20 ms 512 KB Output is correct
4 Correct 23 ms 492 KB Output is correct
5 Correct 466 ms 876 KB Output is correct
6 Correct 316 ms 876 KB Output is correct
7 Correct 556 ms 748 KB Output is correct
8 Correct 491 ms 876 KB Output is correct
9 Correct 488 ms 748 KB Output is correct
10 Correct 605 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -