QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#562584 | #3948. Equilibrium | LaVuna47 | WA | 29ms | 15188kb | C++17 | 2.9kb | 2024-09-13 18:57:29 | 2024-09-13 18:57:33 |
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(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
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
3 0 1 0 2
output:
2 0 1
result:
ok good solution!
Test #2:
score: -100
Wrong Answer
time: 29ms
memory: 15188kb
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 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:
wrong answer not optimal: 199996 VS 2