# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
37393 | HardNut | 관광지 (IZhO14_shymbulak) | C++14 | 1500 ms | 8412 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |