QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#562581#3948. EquilibriumLaVuna47WA 31ms15120kbC++172.9kb2024-09-13 18:56:122024-09-13 18:56:16

Judging History

This is the latest submission verdict.

  • [2024-09-13 18:56:16]
  • Judged
  • Verdict: WA
  • Time: 31ms
  • Memory: 15120kb
  • [2024-09-13 18:56:12]
  • 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_greater();
		else
		    a[to] = get_smaller();
		++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
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3828kb

input:

3
0 1
0 2

output:

1 0 2 

result:

ok good solution!

Test #2:

score: 0
Accepted
time: 30ms
memory: 15120kb

input:

100000
58784 50736
50736 98056
98056 61001
61001 55439
55439 46024
46024 1386
1386 78115
78115 53194
53194 76434
76434 77271
77271 2855
2855 60889
60889 30950
30950 72572
72572 1535
1535 78655
78655 79088
79088 94854
94854 45358
45358 8364
8364 12265
12265 69911
69911 75129
75129 66732
66732 98949
9...

output:

58784 50736 98056 61001 55439 46024 1386 78115 53194 76434 77271 2855 60889 30950 72572 1535 78655 79088 94854 45358 8364 12265 69911 75129 66732 98949 63317 1865 34921 19626 73111 21781 79961 69929 7656 88737 80093 92154 70562 60521 74303 32867 78992 27711 49599 11746 2174 75491 6351 88613 65874 14...

result:

ok good solution!

Test #3:

score: 0
Accepted
time: 28ms
memory: 13148kb

input:

100000
7423 36033
36033 19131
19131 93096
93096 62722
62722 92419
92419 78523
78523 11358
11358 84538
84538 79097
79097 98381
98381 58714
58714 37354
37354 16773
16773 61565
61565 10663
10663 11580
11580 40470
40470 46363
46363 66423
66423 6136
6136 38073
38073 84516
84516 19934
19934 35336
35336 58...

output:

7423 36033 19131 93096 62722 92419 78523 11358 84538 79097 98381 58714 37354 16773 61565 10663 11580 40470 46363 66423 6136 38073 84516 19934 35336 58434 63894 22934 46183 8569 93227 18878 858 37761 29299 55185 54849 22185 74755 21688 56766 42279 87619 35313 15297 93247 98512 27053 65473 87006 65321...

result:

ok good solution!

Test #4:

score: 0
Accepted
time: 28ms
memory: 14152kb

input:

100000
90005 66169
66169 21357
21357 25961
25961 38261
38261 93040
93040 40933
40933 75628
75628 19408
19408 31174
31174 62973
62973 30994
30994 64094
64094 13146
13146 31750
31750 45276
45276 47829
47829 40028
40028 31532
31532 86678
86678 60345
60345 79483
79483 36534
36534 72691
72691 58778
58778...

output:

90005 66169 21357 25961 38261 93040 40933 75628 19408 31174 62973 30994 64094 13146 31750 45276 47829 40028 31532 86678 60345 79483 36534 72691 58778 69625 20414 31858 27844 67670 89741 31244 73261 62676 68474 59857 10922 91017 85179 3470 9431 77824 37453 79805 57031 75545 31095 57753 78472 33849 82...

result:

ok good solution!

Test #5:

score: 0
Accepted
time: 24ms
memory: 14652kb

input:

100000
16544 41366
41366 37711
37711 17730
17730 46166
46166 55790
55790 75285
75285 47950
47950 26223
26223 12387
12387 29819
29819 74930
74930 89091
89091 75669
75669 54428
54428 88769
88769 13690
13690 12514
12514 19185
19185 17480
17480 13777
13777 70811
70811 87495
87495 55464
55464 90043
90043...

output:

16544 41366 37711 17730 46166 55790 75285 47950 26223 12387 29819 74930 89091 75669 54428 88769 13690 12514 19185 17480 13777 70811 87495 55464 90043 6396 32406 71724 38920 69524 60681 36301 24474 93937 96126 7379 39718 3631 59419 40253 29750 30630 31856 88074 45533 68699 21550 36451 73969 18787 561...

result:

ok good solution!

Test #6:

score: -100
Wrong Answer
time: 31ms
memory: 9716kb

input:

100000
0 1
0 2
2 3
1 4
1 5
4 6
6 7
2 8
4 9
0 10
0 11
0 12
4 13
1 14
5 15
14 16
15 17
13 18
9 19
15 20
16 21
20 22
8 23
23 24
7 25
11 26
5 27
3 28
25 29
6 30
26 31
22 32
8 33
19 34
15 35
19 36
22 37
21 38
18 39
2 40
28 41
16 42
18 43
12 44
14 45
20 46
12 47
4 48
15 49
16 50
30 51
40 52
23 53
0 54
32 ...

output:

75217 5075 65345 42851 38662 79892 47235 28152 21391 96273 74413 72862 86529 44720 83161 39877 99951 91817 73147 83643 70456 46469 81584 75654 53090 15928 13284 18873 57252 12494 21627 94978 69464 95081 82127 71631 77891 30961 28648 91740 94509 93510 79437 94636 49344 47542 37416 35425 44336 94127 4...

result:

wrong answer not optimal: 83882 VS 66546