QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#562855 | #3948. Equilibrium | LaVuna47 | WA | 36ms | 15540kb | C++17 | 3.1kb | 2024-09-13 21:37:56 | 2024-09-13 21:37:56 |
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();
}
if(sz(G[v]) % 2 == 0)
{
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;
}
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)
{
int k = 0;
FOR(i, n)
{
if(sz(G[i]) % 2 == 0)
++k;
}
FOR(i, n)
{
if(sz(G[i]) % 2 == 0)
{
int ctr = 0;
for(auto to: G[i])
{
if(a[to] > a[i])
++ctr;
else
--ctr;
}
if(ctr != 0)
return false;
else
--k;
}
}
return k == 0;
}
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];
});
vector<int> marker(n);
FOR(i, n)
{
marker[res[i]] = i;
}
assert(check(G, n, marker));
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: 3720kb
input:
3 0 1 0 2
output:
2 0 1
result:
ok good solution!
Test #2:
score: 0
Accepted
time: 31ms
memory: 15540kb
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: 34ms
memory: 13412kb
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: 31ms
memory: 14540kb
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: 15416kb
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: -100
Wrong Answer
time: 32ms
memory: 10076kb
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 93425 98036 92356 75542 45556 40519 67880 12503 78990 35837 7462 97048 81037 98059 63054 50938 80470 31204 61457 73549 54440 91458 34963 48632 30766 23943 56079 29635 20628 82300 83688 69888 31377 29523 86742 83793 64708 40789 32961 65122 54959 4053 29880 53808 77563 419...
result:
wrong answer not optimal: 83882 VS 66546