Submission #38725889


Source Code Expand

#include<bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
template<typename T> void chkmn(T &a, const T &b)
{
	(a > b) && (a = b);
}
template<typename T> void chkmx(T &a, const T &b)
{
	(a < b) && (a = b);
}
int inc(const int &a, const int &b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}
int dec(const int &a, const int &b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}
int mul(const int &a, const int &b)
{
	return 1LL * a * b % MOD;
}
void Inc(int &a, const int &b)
{
	((a += b) >= MOD) && (a -= MOD);
}
void Dec(int &a, const int &b)
{
	((a -= b) < 0) && (a += MOD);
}
const int N = 2e5 + 5;
struct Lexington
{
	int e, ne;
};
struct Sakawa
{
	int idx, h[N];
	Lexington lxt[2 * N];
	void add(int a, int b)
	{
		lxt[++idx] = (Lexington){b, h[a]};
		h[a] = idx;
	}
	void adds(int a, int b)
	{
		add(a, b), add(b, a);
	}
	int depth[N];
	void dfs(int u, int fa)
	{
		depth[u] = depth[fa] + 1;
		for(int i = h[u]; i; i = lxt[i].ne)
		{
			int v = lxt[i].e;
			if(v == fa) continue;
			dfs(v, u);
		}
	}
}skw;
int n, qwq[N], ans;
int ds[N], dt[N];
int d, D, cnt[N];
int main()
{
	scanf("%d", &n);
	qwq[0] = 1;
	for(int i = 1; i <= n; ++i)
		qwq[i] = mul(qwq[i - 1], 2);
	for(int i = 1; i < n; ++i)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		skw.adds(a, b);
	}
	skw.dfs(1, 0);
	int S = 1;
	for(int i = 1; i <= n; ++i)
		if(skw.depth[i] > skw.depth[S])
			S = i;
	skw.dfs(S, 0);
	int T = 1;
	for(int i = 1; i <= n; ++i)
	{
		ds[i] = skw.depth[i] - 1;
		if(ds[i] > ds[T]) T = i;
	}
	skw.dfs(T, 0);
	D = skw.depth[S] - 1;
	for(int i = 1; i <= n; ++i)
	{
		dt[i] = skw.depth[i] - 1;
		chkmx(d, min(ds[i], dt[i]));
		cnt[max(ds[i], dt[i])]++;
	}
	for(int i = 1; i <= n; ++i)
		cnt[i] += cnt[i - 1];
	for(int i = 0; i < d; ++i)
		Inc(ans, qwq[n]);
	for(int i = d; i < D; ++i)
		Inc(ans, dec(qwq[n], qwq[cnt[i] + 1]));
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task F - Paint Tree
User Schucking_Sattin
Language C++ (GCC 9.2.1)
Score 900
Code Size 1980 Byte
Status AC
Exec Time 87 ms
Memory 20008 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:68:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   68 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
./Main.cpp:75:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   75 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 43
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 8 ms 3600 KiB
random_02.txt AC 66 ms 11516 KiB
random_03.txt AC 36 ms 7268 KiB
random_04.txt AC 7 ms 4160 KiB
random_05.txt AC 53 ms 9784 KiB
random_06.txt AC 5 ms 3904 KiB
random_07.txt AC 45 ms 8596 KiB
random_08.txt AC 19 ms 5272 KiB
random_09.txt AC 64 ms 11236 KiB
random_10.txt AC 23 ms 5228 KiB
random_11.txt AC 2 ms 3828 KiB
random_12.txt AC 68 ms 11628 KiB
random_13.txt AC 61 ms 11180 KiB
random_14.txt AC 28 ms 6700 KiB
random_15.txt AC 50 ms 9804 KiB
random_16.txt AC 35 ms 9900 KiB
random_17.txt AC 87 ms 20008 KiB
random_18.txt AC 19 ms 7240 KiB
random_19.txt AC 85 ms 19984 KiB
random_20.txt AC 46 ms 12832 KiB
random_21.txt AC 13 ms 5212 KiB
random_22.txt AC 44 ms 10228 KiB
random_23.txt AC 13 ms 5136 KiB
random_24.txt AC 58 ms 12368 KiB
random_25.txt AC 13 ms 5220 KiB
random_26.txt AC 39 ms 9292 KiB
random_27.txt AC 12 ms 4516 KiB
random_28.txt AC 43 ms 10516 KiB
random_29.txt AC 28 ms 7352 KiB
random_30.txt AC 50 ms 10368 KiB
random_31.txt AC 23 ms 5848 KiB
random_32.txt AC 15 ms 5468 KiB
random_33.txt AC 39 ms 8704 KiB
random_34.txt AC 6 ms 4168 KiB
random_35.txt AC 38 ms 8728 KiB
random_36.txt AC 33 ms 6756 KiB
random_37.txt AC 46 ms 10028 KiB
random_38.txt AC 15 ms 5352 KiB
random_39.txt AC 50 ms 9992 KiB
random_40.txt AC 25 ms 6788 KiB
sample_01.txt AC 4 ms 3736 KiB
sample_02.txt AC 2 ms 3732 KiB
sample_03.txt AC 2 ms 3740 KiB