답안 #173306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173306 2020-01-03T18:17:34 Z MvC Hard route (IZhO17_road) C++11
52 / 100
785 ms 62712 KB
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=5e3+50;
const int mod=1e9+7;
using namespace std;
int n,i,j,t,u,v,x,y,p,mx,mxl[nmax],lvl[nmax],pr[nmax],rs,cur,cnt,nr,c,ps[nmax][nmax];
vector<int>a[nmax],lf;
vector<pair<int,int> >d[nmax];
vector<vector<pair<int,int> > >lv[nmax];
void bas(int x,int p,int l)
{
	pr[x]=p;
	lvl[x]=mxl[x]=l;
	for(int i=0;i<(int)a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		bas(y,x,l+1);
		mxl[x]=max(mxl[x],mxl[y]);
		d[x].pb(mkp(mxl[y]-lvl[x],y));
	}
}
void dis(int x,int p,int l)
{
	mx=max(mx,l);
	for(int i=0;i<(int)a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		dis(y,x,l+1);
	}
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
		ps[x][y]=(int)a[x].size()-1;
		ps[y][x]=(int)a[y].size()-1;
	}
	for(i=1;i<=n;i++)lv[i].resize((int)a[i].size()+3);
	bas(1,0,0);
	for(i=2;i<=n;i++)
	{
		mx=0;
		dis(pr[i],i,0);
		d[i].pb(mkp(mx+1,pr[i]));
		if((int)a[i].size()==1)lf.pb(i);
	}
	for(i=1;i<=n;i++)
	{
		sort(d[i].begin(),d[i].end());
		reverse(d[i].begin(),d[i].end());
	}
	for(i=0;i<(int)lf.size();i++)
	{
		x=lf[i],mx=0,nr=0,c=0;
		while(x)
		{
			lv[x][ps[x][c]].pb(mkp(nr,mx));
			cur=-1;
			for(j=0;j<(int)d[x].size();j++)
			{
				if(d[x][j].sc!=c && d[x][j].sc!=pr[x])
				{
					cur=d[x][j].fr;
					break;
				}
			}
			if(cur!=-1)mx=max(mx,cur);
			c=x,x=pr[x],nr++;
		}
	}
	for(i=1;i<=n;i++)
	{
		for(j=0;j<(int)a[i].size();j++)
		{
			x=a[i][j];
			if(x==pr[i])continue;
			for(t=j+1;t<(int)a[i].size();t++)
			{
				y=a[i][t];
				if(y==pr[i])continue;
				mx=0;
				for(p=0;p<(int)d[i].size();p++)
				{
					if(d[i][p].sc!=x && d[i][p].sc!=y)
					{
						mx=d[i][p].fr;
						break;
					}
				}
				for(u=0;u<(int)lv[i][ps[i][x]].size();u++)
				{
					for(v=0;v<(int)lv[i][ps[i][y]].size();v++)
					{
						cur=max(mx,max(lv[i][ps[i][x]][u].sc,lv[i][ps[i][y]][v].sc))*(lv[i][ps[i][x]][u].fr+lv[i][ps[i][y]][v].fr);
						if(rs==cur)cnt++;
						else if(rs<cur)rs=cur,cnt=1;
					}
				}
			}
		}
	}
	if((int)a[1].size()==1)
	{
		for(i=0;i<(int)a[1].size();i++)
		{
			x=a[1][i];
			for(j=0;j<(int)lv[1][ps[1][x]].size();j++)
			{
				cur=lv[1][ps[1][x]][j].fr*lv[1][ps[1][x]][j].sc;
				if(rs==cur)cnt++;
				else if(rs<cur)rs=cur,cnt=1;
			}
		}
	}
	cout<<rs<<" "<<cnt<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1192 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1188 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1192 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1188 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 3 ms 1144 KB Output is correct
25 Correct 589 ms 57160 KB Output is correct
26 Correct 451 ms 42104 KB Output is correct
27 Correct 444 ms 36992 KB Output is correct
28 Correct 442 ms 37240 KB Output is correct
29 Correct 513 ms 57852 KB Output is correct
30 Correct 526 ms 62712 KB Output is correct
31 Correct 538 ms 62540 KB Output is correct
32 Correct 462 ms 55724 KB Output is correct
33 Correct 331 ms 38264 KB Output is correct
34 Correct 360 ms 38264 KB Output is correct
35 Correct 355 ms 37872 KB Output is correct
36 Correct 356 ms 38040 KB Output is correct
37 Correct 702 ms 37976 KB Output is correct
38 Correct 480 ms 38520 KB Output is correct
39 Correct 702 ms 38008 KB Output is correct
40 Correct 785 ms 37888 KB Output is correct
41 Correct 762 ms 37712 KB Output is correct
42 Correct 727 ms 37368 KB Output is correct
43 Correct 741 ms 36964 KB Output is correct
44 Correct 704 ms 35960 KB Output is correct
45 Correct 498 ms 32632 KB Output is correct
46 Correct 260 ms 27256 KB Output is correct
47 Correct 378 ms 29060 KB Output is correct
48 Correct 473 ms 22520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1192 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 3 ms 1188 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 3 ms 1144 KB Output is correct
25 Correct 589 ms 57160 KB Output is correct
26 Correct 451 ms 42104 KB Output is correct
27 Correct 444 ms 36992 KB Output is correct
28 Correct 442 ms 37240 KB Output is correct
29 Correct 513 ms 57852 KB Output is correct
30 Correct 526 ms 62712 KB Output is correct
31 Correct 538 ms 62540 KB Output is correct
32 Correct 462 ms 55724 KB Output is correct
33 Correct 331 ms 38264 KB Output is correct
34 Correct 360 ms 38264 KB Output is correct
35 Correct 355 ms 37872 KB Output is correct
36 Correct 356 ms 38040 KB Output is correct
37 Correct 702 ms 37976 KB Output is correct
38 Correct 480 ms 38520 KB Output is correct
39 Correct 702 ms 38008 KB Output is correct
40 Correct 785 ms 37888 KB Output is correct
41 Correct 762 ms 37712 KB Output is correct
42 Correct 727 ms 37368 KB Output is correct
43 Correct 741 ms 36964 KB Output is correct
44 Correct 704 ms 35960 KB Output is correct
45 Correct 498 ms 32632 KB Output is correct
46 Correct 260 ms 27256 KB Output is correct
47 Correct 378 ms 29060 KB Output is correct
48 Correct 473 ms 22520 KB Output is correct
49 Runtime error 8 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Halted 0 ms 0 KB -