Submission #667659

# Submission time Handle Problem Language Result Execution time Memory
667659 2022-12-01T21:07:31 Z dozer Star Trek (CEOI20_startrek) C++14
7 / 100
3 ms 2676 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 pb push_back
#define endl "\n"
#define sp " "
#define pii pair<int, int>
#define st first
#define nd second
#define N 100005
#define int long long

const int modulo = 1e9 + 7;
vector<pii> adj[N];
int dp[N][2][2], edge[N][2];


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

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


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

int fe(int a, int b)
{
	if (b == 0) return 1;
	if (b % 2) return mul(a, fe(a, b - 1));
	int tmp = fe(a, b / 2);
	return mul(tmp, tmp);
}

int f(int i, int j, int turn)
{
	if (dp[i][j][turn] != -1) return dp[i][j][turn];
	int node = edge[i][j];
	int root = edge[i][1 - j];
	if (adj[node].size() == 1)
	{
		if (turn == 1) return 1;
		return 0;
	}
	int ans = 0;
	if (turn == 0) ans = 1;
	for (auto k : adj[node])
	{
		int curr = edge[k.st][k.nd];
		if (curr == root) continue;
		if (turn == 1) ans |= f(k.st, k.nd, turn ^ 1);
		if (turn == 0) ans &= f(k.st, k.nd, turn ^ 1);
	}
	return dp[i][j][turn] = ans;
}

int32_t main()
{
	//fileio();
	fastio();

	int n, d;
	cin>>n>>d;
	for (int i = 1; i <= n; i++)
	{
		int u, v;
		cin>>u>>v;
		adj[u].pb({i, 1});
		adj[v].pb({i, 0});
		edge[i][0] = u;
		edge[i][1] = v;
	}

	cout<<fe(4, d)<<endl;

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 3 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -