QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#563029 | #3948. Equilibrium | LaVuna47 | AC ✓ | 46ms | 15068kb | C++17 | 2.6kb | 2024-09-14 00:31:18 | 2024-09-14 00:31:19 |
Judging History
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();
}
int par = 0;
if(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();
}
else ++set_ctr;
}
for(auto to: G[v])
{
if(to != pr)
{
f(to, v, G, a);
}
}
}
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 = 10000000, R = 10000000+1;
vector<int> a(n, -1);
a[0] = get_greater();
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: 1ms
memory: 3620kb
input:
3 0 1 0 2
output:
2 0 1
result:
ok good solution!
Test #2:
score: 0
Accepted
time: 43ms
memory: 15068kb
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:
98970 40470 15926 67532 80381 54637 76610 11622 86012 53512 76758 36068 77901 728 44520 85646 87753 17474 94098 52469 92480 79013 23114 69144 68169 23470 90042 13471 83461 48741 69626 98213 88849 5787 14310 67978 57298 72772 78921 88499 81169 85409 96629 33376 73374 60002 39064 82912 73147 67683 818...
result:
ok good solution!
Test #3:
score: 0
Accepted
time: 46ms
memory: 13164kb
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:
59038 47353 68128 87879 82130 50826 90731 57511 18024 55234 23324 52902 82985 9911 86242 6952 17266 49404 38169 57698 27914 87280 86619 21068 72471 12449 83441 96078 1062 63479 67631 26213 97070 17023 28167 83753 55458 55595 21254 90469 93746 33690 65770 5849 53379 24338 30541 23671 52423 40285 5308...
result:
ok good solution!
Test #4:
score: 0
Accepted
time: 42ms
memory: 14360kb
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:
3565 34361 85395 7889 74917 6039 15843 61072 71190 8454 11151 14039 56676 98612 26634 53874 82704 52883 35896 90093 48862 96420 27084 20894 76547 29411 9866 47008 44206 16443 39632 15116 56041 42592 54007 75526 83607 81003 78665 80589 19063 90613 65912 88999 4456 8727 87338 18041 81549 60507 3867 42...
result:
ok good solution!
Test #5:
score: 0
Accepted
time: 36ms
memory: 14804kb
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:
455 48835 45088 10564 63355 62827 2575 93989 52238 29961 25789 6184 41005 17894 38919 1233 65319 68243 44780 81838 41504 77721 18779 16806 68848 72163 6164 63555 86722 71431 47346 70374 19206 88661 41021 39080 68671 92960 21024 87509 95324 75314 49884 14299 75280 49126 40726 90457 42530 33749 90272 ...
result:
ok good solution!
Test #6:
score: 0
Accepted
time: 42ms
memory: 9452kb
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:
91275 94584 60382 64015 2464 42851 38662 93425 96273 98036 92356 75542 45556 40519 83643 91817 70456 75654 13284 67880 12503 78990 35837 7462 97048 81037 98059 63054 50938 80470 31204 77891 95081 71631 61457 93510 79437 73549 47542 54440 91458 34963 48632 30766 23943 56079 29635 20628 85883 84368 99...
result:
ok good solution!
Test #7:
score: 0
Accepted
time: 40ms
memory: 9472kb
input:
100000 0 1 0 2 2 3 3 4 1 5 1 6 5 7 7 8 8 9 3 10 4 11 6 12 2 13 6 14 11 15 7 16 9 17 2 18 14 19 16 20 8 21 13 22 10 23 4 24 14 25 17 26 16 27 7 28 25 29 15 30 15 31 25 32 15 33 18 34 27 35 14 36 0 37 14 38 7 39 15 40 38 41 13 42 0 43 31 44 41 45 3 46 35 47 32 48 11 49 25 50 21 51 39 52 25 53 53 54 45...
output:
45202 34336 84981 45560 58684 12986 31776 29594 21787 57176 15744 99946 78209 99683 70274 56701 27407 87082 87073 96836 37042 34797 37549 90880 29599 68729 19453 15271 85925 30884 6406 97519 13755 5288 97378 81970 78186 42541 65211 29499 87442 61342 48299 42495 38815 73423 69087 42073 33036 8274 601...
result:
ok good solution!
Test #8:
score: 0
Accepted
time: 37ms
memory: 9616kb
input:
100000 0 1 0 2 0 3 3 4 0 5 1 6 0 7 4 8 2 9 6 10 6 11 6 12 1 13 11 14 14 15 2 16 5 17 5 18 13 19 19 20 19 21 19 22 1 23 19 24 5 25 6 26 23 27 24 28 25 29 22 30 27 31 29 32 15 33 24 34 13 35 13 36 36 37 19 38 7 39 16 40 39 41 22 42 4 43 2 44 3 45 29 46 19 47 17 48 27 49 42 50 4 51 46 52 19 53 50 54 53...
output:
88475 97717 94102 61127 38293 30851 56773 54798 47476 65945 54674 43638 27250 52924 51195 49652 85687 52025 31034 20339 93235 36887 37363 23166 9279 15920 7012 95618 68680 92340 61341 52842 32402 97696 57964 63593 14647 8659 98756 35104 21524 16360 6694 62147 39844 12492 40494 31706 64828 23121 6631...
result:
ok good solution!
Test #9:
score: 0
Accepted
time: 42ms
memory: 9680kb
input:
100000 0 1 1 2 0 3 3 4 3 5 5 6 6 7 5 8 8 9 4 10 7 11 2 12 3 13 8 14 6 15 2 16 9 17 15 18 5 19 4 20 18 21 5 22 9 23 7 24 5 25 3 26 16 27 14 28 2 29 25 30 29 31 27 32 27 33 26 34 16 35 17 36 29 37 17 38 9 39 16 40 16 41 40 42 31 43 9 44 37 45 35 46 38 47 25 48 27 49 2 50 39 51 1 52 49 53 15 54 29 55 1...
output:
58437 83606 79603 40819 34939 36935 46462 32605 31598 50298 91540 61791 81952 45108 93017 78566 63231 81079 38830 25149 18297 46300 89330 28800 36875 16255 29957 14241 79676 76342 75599 34527 8413 92191 55302 48222 69699 99298 55059 82823 28676 24307 77965 64728 20220 15433 97983 13810 90832 63720 9...
result:
ok good solution!
Test #10:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
16 0 1 1 2 0 3 2 4 2 5 3 6 5 7 1 8 1 9 8 10 4 11 0 12 9 13 11 14 12 15
output:
6 10 7 5 8 3 0 1 12 2 9 4 11 14 13 15
result:
ok good solution!
Test #11:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
16 0 1 1 2 0 3 0 4 3 5 4 6 2 7 5 8 4 9 1 10 3 11 3 12 3 13 1 14 12 15
output:
9 15 8 12 5 10 3 0 1 4 2 14 7 11 13 6
result:
ok good solution!
Test #12:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
16 0 1 0 2 1 3 3 4 3 5 0 6 0 7 0 8 0 9 4 10 0 11 10 12 2 13 2 14 1 15
output:
13 5 15 9 7 2 0 1 6 8 11 3 4 10 12 14
result:
ok good solution!
Test #13:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
16 0 1 0 2 2 3 2 4 4 5 2 6 5 7 2 8 0 9 1 10 3 11 8 12 4 13 4 14 8 15
output:
15 13 11 6 3 2 0 1 9 10 4 8 5 14 7 12
result:
ok good solution!
Test #14:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
16 0 1 1 2 0 3 1 4 2 5 1 6 5 7 1 8 8 9 4 10 4 11 10 12 5 13 0 14 1 15
output:
9 12 10 13 8 4 3 0 1 14 2 6 15 5 7 11
result:
ok good solution!
Test #15:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
16 0 1 0 2 2 3 0 4 1 5 3 6 4 7 6 8 5 9 7 10 4 11 1 12 10 13 12 14 0 15
output:
11 8 6 3 14 12 15 2 0 1 4 5 9 7 10 13
result:
ok good solution!
Test #16:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
16 0 1 1 2 2 3 3 4 1 5 4 6 6 7 1 8 3 9 0 10 5 11 10 12 6 13 11 14 10 15
output:
12 14 11 13 9 5 10 0 1 2 8 3 4 6 7 15
result:
ok good solution!
Test #17:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
16 0 1 0 2 2 3 0 4 2 5 0 6 4 7 5 8 3 9 0 10 3 11 0 12 0 13 8 14 0 15
output:
9 3 15 12 6 2 0 1 4 10 13 5 11 8 14 7
result:
ok good solution!
Test #18:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
16 0 1 1 2 0 3 0 4 2 5 0 6 1 7 6 8 1 9 9 10 8 11 8 12 3 13 7 14 2 15
output:
11 8 13 14 15 7 6 3 0 1 4 2 9 5 10 12
result:
ok good solution!
Test #19:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
16 0 1 1 2 1 3 3 4 3 5 5 6 6 7 5 8 8 9 1 10 2 11 8 12 4 13 11 14 3 15
output:
9 8 13 15 4 3 0 1 2 10 11 14 5 6 7 12
result:
ok good solution!
Test #20:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
16 0 1 1 2 1 3 1 4 0 5 5 6 3 7 0 8 0 9 7 10 3 11 2 12 12 13 7 14 7 15
output:
6 15 10 7 3 9 5 0 1 8 2 4 12 13 11 14
result:
ok good solution!
Test #21:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
16 0 1 0 2 2 3 0 4 3 5 1 6 4 7 7 8 6 9 5 10 5 11 7 12 6 13 11 14 11 15
output:
12 15 10 5 3 13 2 0 1 4 6 9 11 14 7 8
result:
ok good solution!
Test #22:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
16 0 1 0 2 1 3 1 4 1 5 4 6 0 7 7 8 4 9 0 10 9 11 6 12 4 13 11 14 11 15
output:
15 12 13 6 4 10 2 0 1 7 3 5 9 11 14 8
result:
ok good solution!
Test #23:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
16 0 1 1 2 0 3 2 4 1 5 0 6 6 7 1 8 3 9 6 10 8 11 5 12 9 13 7 14 3 15
output:
10 13 9 12 5 3 0 1 6 2 8 4 11 15 7 14
result:
ok good solution!
Test #24:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
16 0 1 1 2 0 3 1 4 3 5 4 6 5 7 4 8 5 9 5 10 3 11 7 12 2 13 12 14 11 15
output:
14 12 10 7 5 6 4 3 0 1 2 13 8 11 9 15
result:
ok good solution!
Test #25:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
16 0 1 1 2 1 3 3 4 2 5 3 6 3 7 6 8 0 9 9 10 6 11 2 12 7 13 4 14 11 15
output:
10 13 15 11 14 7 4 12 3 9 0 1 2 5 6 8
result:
ok good solution!
Test #26:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
16 0 1 0 2 2 3 1 4 0 5 1 6 0 7 7 8 0 9 2 10 7 11 6 12 6 13 11 14 2 15
output:
8 15 3 12 6 7 2 0 1 5 9 4 13 10 11 14
result:
ok good solution!
Test #27:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
16 0 1 0 2 1 3 3 4 0 5 5 6 0 7 1 8 4 9 2 10 5 11 1 12 6 13 7 14 13 15
output:
14 11 10 8 7 2 0 1 5 3 12 4 9 6 13 15
result:
ok good solution!
Test #28:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
16 0 1 1 2 2 3 3 4 2 5 4 6 2 7 6 8 2 9 8 10 4 11 3 12 2 13 0 14 0 15
output:
11 12 9 5 14 0 1 15 2 3 7 13 4 6 8 10
result:
ok good solution!
Test #29:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
16 0 1 1 2 0 3 0 4 0 5 0 6 2 7 0 8 3 9 6 10 9 11 4 12 8 13 9 14 12 15
output:
13 11 9 8 5 3 0 1 4 6 2 7 14 12 15 10
result:
ok good solution!
Test #30:
score: 0
Accepted
time: 34ms
memory: 9808kb
input:
100000 58784 50736 58784 98056 58784 61001 58784 55439 58784 46024 58784 1386 58784 78115 58784 53194 58784 76434 58784 77271 58784 2855 58784 60889 58784 30950 58784 72572 58784 1535 58784 78655 58784 79088 58784 94854 58784 45358 58784 8364 58784 12265 58784 69911 58784 75129 58784 66732 58784 989...
output:
98970 15926 80381 76610 86012 76758 77901 44520 87753 94098 92480 23114 68169 90042 83461 69626 88849 14310 57298 78921 81169 96629 73374 39064 73147 81833 78589 72414 11327 44050 97578 54198 17237 19883 62571 92516 4679 6158 35152 76835 98586 63938 49488 97761 32478 69686 3747 6976 85142 99506 8033...
result:
ok good solution!
Test #31:
score: 0
Accepted
time: 36ms
memory: 9796kb
input:
100000 7423 36033 7423 19131 7423 93096 7423 62722 7423 92419 7423 78523 7423 11358 7423 84538 7423 79097 7423 98381 7423 58714 7423 37354 7423 16773 7423 61565 7423 10663 7423 11580 7423 40470 7423 46363 7423 66423 7423 6136 7423 38073 7423 84516 7423 19934 7423 35336 7423 58434 7423 63894 7423 229...
output:
59038 68128 82130 90731 18024 23324 82985 86242 17266 38169 27914 86619 72471 83441 1062 67631 97070 28167 55458 21254 93746 65770 53379 30541 52423 5308 96723 9873 26253 22322 35937 70638 34953 28947 41540 62654 50950 2005 86611 36192 73276 72229 88778 12360 63555 98901 66489 40942 85477 44899 5993...
result:
ok good solution!
Test #32:
score: 0
Accepted
time: 35ms
memory: 9860kb
input:
100000 90005 66169 90005 21357 90005 25961 90005 38261 90005 93040 90005 40933 90005 75628 90005 19408 90005 31174 90005 62973 90005 30994 90005 64094 90005 13146 90005 31750 90005 45276 90005 47829 90005 40028 90005 31532 90005 86678 90005 60345 90005 79483 90005 36534 90005 72691 90005 58778 90005...
output:
3565 85395 74917 15843 71190 11151 56676 26634 82704 35896 48862 27084 76547 9866 44206 39632 56041 54007 83607 78665 19063 65912 4456 87338 81549 3867 49405 78897 8750 20423 33861 15946 99661 15809 638 29804 72422 70876 36035 8368 33535 36268 92782 4295 95795 25030 37724 14268 68936 79076 23317 792...
result:
ok good solution!
Test #33:
score: 0
Accepted
time: 24ms
memory: 9764kb
input:
100000 16544 41366 16544 37711 16544 17730 16544 46166 16544 55790 16544 75285 16544 47950 16544 26223 16544 12387 16544 29819 16544 74930 16544 89091 16544 75669 16544 54428 16544 88769 16544 13690 16544 12514 16544 19185 16544 17480 16544 13777 16544 70811 16544 87495 16544 55464 16544 90043 16544...
output:
455 45088 63355 2575 52238 25789 41005 38919 65319 44780 41504 18779 68848 6164 86722 47346 19206 41021 68671 21024 95324 49884 75280 40726 42530 90272 9470 70253 60858 53749 58481 42411 80048 10558 68814 69117 50918 49992 90978 79625 27496 54028 1689 85513 15584 96418 74731 64115 56812 35066 3698 7...
result:
ok good solution!