제출 #316648

#제출 시각아이디문제언어결과실행 시간메모리
316648shrek12357관광지 (IZhO14_shymbulak)C++14
50 / 100
630 ms888 KiB
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <set> #include <climits> #include <cmath> #include <fstream> #include <queue> #include <stack> #include <bitset> using namespace std; #define ll long long //cin.tie(0);ios_base::sync_with_stdio(0); const int MAXN = 5005; int n; vector<int> adjList[MAXN]; int cur = 0, cnt = 0; void bfs(int src) { int dist[MAXN]; for (int i = 0; i < MAXN; i++) { dist[i] = INT_MAX; } queue<int> q; q.push(src); dist[src] = 0; while (q.size() > 0) { int cn = q.front(); q.pop(); for (auto i : adjList[cn]) { if (dist[i] >= dist[cn] + 1) { q.push(i); dist[i] = dist[cn] + 1; if (cur == dist[i]) { cnt++; } else if (cur < dist[i]) { cur = dist[i]; cnt = 1; } } } } } int main() { cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; a--; b--; adjList[a].push_back(b); adjList[b].push_back(a); } int ans = 0, best = 0; for (int i = 0; i < n; i++) { cur = 0; cnt = 0; bfs(i); if (cur == ans) { best += cnt; } else if (cur > ans) { ans = cur; best = cnt; } } cout << best/2 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...