QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725889#2376. Game on a TreeLaVuna47#Compile Error//C++202.5kb2024-11-08 20:30:312024-11-08 20:30:32

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 20:30:32]
  • 评测
  • [2024-11-08 20:30:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;


vector<int> win_ctr, lose_ctr;
vector<bool> is_win;
vector<vector<int>> adj;

void f(int v, int pr)
{
	win_ctr[v] = 0;
	lose_ctr[v] = 0;
	for(auto to: adj[v])
	{
		if(to != pr)
		{
			f(to, v);
			if(is_win[to])
				win_ctr[v] += 1;
			else
				lose_ctr[v] += 1;
		}
	}
	is_win[v] = (lose_ctr[v] > 0);
}


// true if there exists losing state v
bool g(int v, int pr)
{
	lose_ctr[v] = 0;
	win_ctr[v] = 0;
	for(auto to: adj[v])
	{ 47
		if(is_win[to])
			win_ctr[to] += 1;
		else
			lose_ctr[to] += 1;
	}
	is_win[v] = (lose_ctr[v] > 0);
	if(lose_ctr[v] == 0)
	{
		cout << "Wtf????\n";
		return true;
	}
	return false;
	for(auto to: adj[v])
	{
		if(to != pr)
		{
			if(is_win[to])
			{
				int v_lose_ctr = lose_ctr[v];
				int to_lose_ctr = lose_ctr[to];
				int v_win_ctr = win_ctr[v];
				int to_win_ctr = win_ctr[to];
				bool is_win_v = is_win[v];
				if(is_win[to])
					win_ctr[v] -= 1;
				else
					lose_ctr[v] -= 1;
				if(lose_ctr[v] == 0)
					is_win[v] = false;
				if(g(to, v))
					return true;
				is_win[v] = is_win_v;
				lose_ctr[v] = v_lose_ctr;
				lose_ctr[to] = to_lose_ctr;
				win_ctr[v]=v_win_ctr;
				win_ctr[to]=to_win_ctr;
			}
		}
	}
	return false;
}

int solve()
{
	int n;
	if (!(cin >> n))
		return 1;
	adj=vector<vector<int>> (n);
	FOR(_,0,n-1)
	{
		int a, b;
		cin >> a >> b;
		--a, --b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	win_ctr = vector<int>(n,0);
	lose_ctr = vector<int>(n,0);
	is_win = vector<bool>(n, false);
	f(0,-1);
	FOR(i,0,n) cout << is_win[i] << ' ';
	FOR(i,0,n)
	{
		cout << win_ctr[i] << ' ' << lose_ctr[i] << '\n';
	}
	
	cout << '\n';
	if(g(0,-1))
		cout << "Alice\n";
	else
		cout << "Bob\n";
	return 0;
}

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int TET = 1e9;
	//cin >> TET;
	for (int i = 1; i <= TET; i++)
	{
		if (solve())
		{
			break;
		}
		#ifdef ONPC
			cerr << "____________________________\n";
		#endif
	}
	#ifdef ONPC
		cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
	#endif
	return 0;
}

Details

answer.code: In function ‘bool g(int, int)’:
answer.code:50:13: error: expected ‘;’ before ‘if’
   50 |         { 47
      |             ^
      |             ;
   51 |                 if(is_win[to])
      |                 ~~
answer.code:53:17: error: ‘else’ without a previous ‘if’
   53 |                 else
      |                 ^~~~