# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91093 | YottaByte | 관광지 (IZhO14_shymbulak) | C++14 | 19 ms | 844 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
const int N = 5001;
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
int n, d[N], u[N];
int ans, mx, root;
vector < int > g[N], v;
void dij(int x, int curd = 1)
{
priority_queue < pair < int, int > > pq;
pq.push( mk( -curd, x ) );
d[x] = curd;
while(!pq.empty())
{
x = pq.top().sc;
curd = -pq.top().fr;
pq.pop();
if(curd > d[x]) continue;
for(int to : g[x])
{
if(d[to] == 0 || d[to] > curd + 1)
{
d[to] = curd + 1;
pq.push( mk( -d[to], to ) );
}
}
}
}
void dfs(int v, int dist = 0, int p = 0)
{
u[v] = 1;
if(dist == mx)
{
//printf("%d\n", v);
ans++;
return;
}
for(int to : g[v])
if(d[to] - 1 == dist + 1)
dfs(to, dist + 1, v);
}
main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
int a, b;
scanf("%d", &a);
scanf("%d", &b);
g[a].pb(b);
g[b].pb(a);
}
for(int i = 1; i <= n; i++)
{
memset(d, 0, sizeof(d)); dij(i);
for(int j = 1; j <= n; j++)
{
if(mx < d[j] - 1)
{
root = i;
mx = d[j] - 1;
}
}
}
memset(d, 0, sizeof(d)); dij(root);
for(int i = 1; i <= n; i++)
{
if(d[i] - 1 == mx)
{
v.pb( i );
}
}
dfs(root);
printf("%d\n", ans);
}
/**
6
1 2
1 3
2 4
4 3
4 5
4 6
**/
컴파일 시 표준 에러 (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... |