Submission #667946

# Submission time Handle Problem Language Result Execution time Memory
667946 2022-12-02T12:01:15 Z dozer Star Trek (CEOI20_startrek) C++14
23 / 100
20 ms 32552 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
//#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 1005
#define int long long

const int modulo = 1e9 + 7;

int mul(int a, int b)
{
	return (a * b) % modulo;
}

int add(int a, int b)
{
	if (a + b < modulo) return a + b;
	return a + b - modulo;
}

int subs(int a, int b)
{
	if (a < b) return a - b + modulo;
	return a - b;
}

int dp[N][N][2], reach[2][N];
vector<int> adj[N];

int f(int node, int root, int turn);

void dfs(int node, int root, int dep, int turn)
{
	int player = dep % 2;
	if (player == turn) reach[turn][node] = 1;
	int cnt = 0;
	for (auto i : adj[node])
	{
		if (i == root) continue;
		if (f(i, node, 1 - player) == 1 - turn) cnt++;
	}
	if (player == turn || cnt == 1)
	{
		for (auto i : adj[node])
		{
			if (i == root) continue;
			if (turn != player && f(i, node, 1 - player) != player) continue;
			dfs(i, node, dep + 1, turn);
		}
	}
}

int f(int node, int root, int turn)
{
	if(dp[node][root][turn] != -1) return dp[node][root][turn];
	int ans = 0;
	if (turn == 0) ans = 1;
	for (auto i : adj[node])
	{
		if (i == root) continue;
		if (turn == 0) ans &= f(i, node, 1 - turn);
		else ans |= f(i, node, 1 - turn);
	}
	return dp[node][root][turn] = ans;
}


int32_t main()
{
	#ifndef ONLINE_JUDGE
	//fileio();
	#endif
	fastio();


	memset(dp, -1, sizeof(dp));
	int n, d;
	cin>>n>>d;
	for (int i = 1; i < n; i++)
	{
		int u, v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	
	int res = f(1, 0, 1);
	int sum = 0;
	int agn = 0, gab = 0;
	for (int i = 1; i <= n; i++) if (f(i, 0, 0)) sum++;
	dfs(1, 0, 1, 0);
	dfs(1, 0, 1, 1);
	for (int i = 1; i <= n; i++) if (reach[1][i]) agn++;
		//cout<<endl;
	for (int i = 1; i <= n; i++) if (reach[0][i]) gab++;
		//cout<<endl;
	int ans = 0;
	if (res == 1)
	{
		ans = mul(n, n);
		ans = subs(ans, mul(sum, gab));
	}
	else
	{
		ans = mul(agn, sum);
	}

	cout<<ans<<endl;
	cerr<<"time taken : "<<clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16084 KB Output is correct
2 Incorrect 7 ms 16084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 16084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 7 ms 16164 KB Output is correct
6 Correct 7 ms 16160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 7 ms 16164 KB Output is correct
6 Correct 7 ms 16160 KB Output is correct
7 Correct 7 ms 16164 KB Output is correct
8 Correct 7 ms 16292 KB Output is correct
9 Correct 8 ms 16104 KB Output is correct
10 Correct 7 ms 16160 KB Output is correct
11 Correct 7 ms 16212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 7 ms 16164 KB Output is correct
6 Correct 7 ms 16160 KB Output is correct
7 Correct 7 ms 16164 KB Output is correct
8 Correct 7 ms 16292 KB Output is correct
9 Correct 8 ms 16104 KB Output is correct
10 Correct 7 ms 16160 KB Output is correct
11 Correct 7 ms 16212 KB Output is correct
12 Runtime error 20 ms 32552 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 7 ms 16164 KB Output is correct
6 Correct 7 ms 16160 KB Output is correct
7 Correct 7 ms 16164 KB Output is correct
8 Correct 7 ms 16292 KB Output is correct
9 Correct 8 ms 16104 KB Output is correct
10 Correct 7 ms 16160 KB Output is correct
11 Correct 7 ms 16212 KB Output is correct
12 Correct 7 ms 16084 KB Output is correct
13 Incorrect 7 ms 16156 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16084 KB Output is correct
4 Correct 6 ms 16084 KB Output is correct
5 Correct 7 ms 16164 KB Output is correct
6 Correct 7 ms 16160 KB Output is correct
7 Correct 7 ms 16164 KB Output is correct
8 Correct 7 ms 16292 KB Output is correct
9 Correct 8 ms 16104 KB Output is correct
10 Correct 7 ms 16160 KB Output is correct
11 Correct 7 ms 16212 KB Output is correct
12 Runtime error 20 ms 32552 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 16084 KB Output is correct
2 Incorrect 7 ms 16084 KB Output isn't correct
3 Halted 0 ms 0 KB -