QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562583#3948. EquilibriumLaVuna47Compile Error//C++172.9kb2024-09-13 18:57:012024-09-13 18:57:01

Judging History

This is the latest submission verdict.

  • [2024-09-13 18:57:01]
  • Judged
  • [2024-09-13 18:57:01]
  • Submitted

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define RFOR(i, n) for(int i = n-1; i >= 0; --i)
#define output_vec(vec) { FOR(i_, sz(vec)) cout << vec[i_] << ' '; cout << '\n'; }
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<bool> vb;
typedef short si;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif


int L, R;

int get_greater()
{
    return ++R;
}

int get_smaller()
{
    return --L;
}

void f(int v, int pr, const vector<vector<int>>& G, vector<int>& a)
{
    if(a[v] == -1)
    {
	a[v] = get_greater();
    }
    if(sz(G[v]) % 2 == 0)
    {
    
	int par = 0;
	if(pr != -1 a[pr] > a[v])
	{
	    ++par;
	}
	int set_ctr = 0;
	for(auto to: G[v])
	{
	    if(a[to] == -1)
	    {
		if(par % 2 == 0)
		    a[to] = get_smaller();
		else
		    a[to] = get_greater();
		++par;
	    }
	    else ++set_ctr;
	}
	assert(set_ctr <= 1);
    }

    for(auto to: G[v])
    {
	if(to != pr)
	{
	    f(to, v, G, a);
	}
    }
}

bool check(vector<vector<int>>& G, int n, vector<int>& a)
{
    FOR(i, n)
    {
	if(sz(G[i]) % 2 == 0)
	{
	    int ctr = 0;
	    for(auto to: G[i])
	    {
		if(a[to] > a[i])
		    ++ctr;
		else if(a[to] < a[i])
		    --ctr;
		else assert(false);
	    }
	    if(ctr != 0)
		return false;
	}
    }
    return true;
}

int solve()
{
    int n;
    if(!(cin >> n))
	return 1;
    vector<vector<int>> G(n);
    FOR(_, n-1)
    {
	int u, v;
	cin >> u >> v;
	G[u].pb(v);
	G[v].pb(u);
    }
    L = 5*n, R = 5*n+4;
    vector<int> a(n, -1);
    f(0, -1, G, a);
    vector<int> res(n);
    iota(all(res), 0);
    sort(all(res), [&](int v1, int v2) -> bool {
	return a[v1] > a[v2]; 
    });
    FOR(i, n) cout << res[i] << ' ';
    cout << '\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
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

Details

answer.code: In function ‘void f(int, int, const std::vector<std::vector<int> >&, std::vector<int>&)’:
answer.code:60:20: error: expected ‘)’ before ‘a’
   60 |         if(pr != -1 a[pr] > a[v])
      |           ~        ^~
      |                    )