| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 93023 | davitmarg | Hard route (IZhO17_road) | C++17 | 2061 ms | 142480 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>  
#include <cassert>
#include <fstream>  
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
const int N = 5003;
int n,used[N][N],st;
vector<int> g[N];
pair<LL, LL> dp[N][N];
LL  best;
map<LL, int> u;
void dfsinit(int v)
{
	used[st][v] = 1;
	for (int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i];
		if (used[st][to] == 1)
			continue;
		dfsinit(to);
		if (dp[st][to].first + 1 >= dp[st][v].first)
		{
			dp[st][v].second = dp[st][v].first;
			dp[st][v].first = dp[st][to].first + 1;
		}
		else if (dp[st][to].first + 1 >= dp[st][v].second)
			dp[st][v].second = dp[st][to].first + 1;
	}
}
void dfs(int v, LL d = 0, LL h = 0)
{
	used[st][v] = 2;
	if (g[v].size() == 1 && st!=v)
	{
		best = max(best, h*d);
		u[h*d]++;
	}
	for (int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i];
		if (used[st][to]==2)
			continue;
		LL H;
		if (dp[st][to].first + 1 == dp[st][v].first)
			H = max(h,dp[st][v].second);
		else
			H = max(h, dp[st][v].first);
		dfs(to,d+1,H);
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n-1; i++)
	{
		int a, b;
		//cin >> a >> b;
		scanf("%d%d",&a,&b);
		g[a].PB(b);
		g[b].PB(a);
	}
	for (st = 1; st <= n; st++)
		if(g[st].size()==1)
		{
			dfsinit(st);
			dfs(st);
		}
	cout << best << " " << u[best] / 2 << endl;
	return 0;
}
/*
*/
컴파일 시 표준 에러 (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... | ||||
