| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 37802 | mirbek01 | 관광지 (IZhO14_shymbulak) | C++14 | 949 ms | 200872 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
# define pb push_back
# define fr first
# define sc second
# define mk make_pair
using namespace std;
const int inf = 1e9 + 7;
const int N = 5e3 + 5;
typedef long long ll;
int n, m, ans, mx, dist[N][N], cnt[N][N];
vector <int> g[N];
void bfs(int x)
{
queue <int> q;
q.push(x);
cnt[x][x] = 1;
// cout << x << endl;
while(!q.empty())
{
int v = q.front();
q.pop();
for(int i = 0; i < g[v].size(); i ++)
{
int to = g[v][i];
if(dist[x][to] == dist[x][v] + 1 || dist[x][to] == 0)
cnt[x][to] += cnt[x][v];
if(!dist[x][to] && to != x)
{
dist[x][to] = dist[x][v] + 1;
q.push(to);
}
}
}
// for(int i = 1; i <= n; i ++)
// cout << dist[x][i] << " ";
// cout << endl;
// for(int i = 1; i <= n; i ++)
// cout << cnt[x][i] << " ";
// cout << endl;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
for(int i = 1; i <= n; i ++)
bfs(i);
for(int i = 1; i <= n; i ++)
for(int j = i + 1; j <= n; j ++)
mx = max(mx, dist[i][j]);
// for(int i = 1; i <= n; i ++)
// {
// for(int j = i + 1; j <= n; j ++)
// {
// cout << i << " " << j << " " << dist[i][j] << " " << cnt[i][j] << endl;
// }
// }
for(int i = 1; i <= n; i ++)
for(int j = i + 1; j <= n; j ++)
if(mx == dist[i][j]) ans += cnt[i][j];
cout << ans << endl;
}
컴파일 시 표준 에러 (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... | ||||
