답안 #667656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667656 2022-12-01T21:05:08 Z dozer Star Trek (CEOI20_startrek) C++14
0 / 100
26 ms 20016 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

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(2, d)<<endl;

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}

Compilation message

startrek.cpp: In function 'int32_t main()':
startrek.cpp:3:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
startrek.cpp:68:2: note: in expansion of macro 'fileio'
   68 |  fileio();
      |  ^~~~~~
startrek.cpp:3:59: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
      |                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
startrek.cpp:68:2: note: in expansion of macro 'fileio'
   68 |  fileio();
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 20016 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 19940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 20016 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -