QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607713 | #6396. Puzzle: Kusabi | lqh2024 | WA | 1ms | 3700kb | C++17 | 4.0kb | 2024-10-03 15:57:04 | 2024-10-03 15:57:04 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
using i64 = long long;
mt19937_64 rd(time(0));
template <class K, class C = less<>> using paring_heap = __gnu_pbds::priority_queue<K, C>;
template <class K> using rb_tree = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class ... A> void debug(const T & t, const A & ... a) { cerr << "[" << t, ((cerr << ", " << a), ...), cerr << "]\n"; }
const i64 mod = [](bool n) { return n ? 998244353 : 1e9 + 7; } (1);
void QAQ() {
int n, m, cnt = 0;
cin >> n;
vector adj(n + 1, vector<int>(m + 1));
vector<int> a(n + 1), dep(n + 1);
for (int i = 2, u, v; i <= n; i++) {
string s;
cin >> u >> v >> s;
if (s[0] == '-') a[u] = 0;
else if (s[0] == 'T') a[u] = 1;
else if (s[0] == 'D') a[u] = 2;
else a[u] = 3;
cnt += !!a[u];
adj[u].emplace_back(v), adj[v].emplace_back(u);
}
struct Info : map<array<int, 2>, int> {
vector<array<int, 2>> res;
Info(int op, int dep, int u) {
insert({{op, dep}, u});
}
void merge(Info && dp, int op) {
if (size() < dp.size()) std::swap(*this, dp);
for (auto & [_, v] : dp) {
auto [sta, len] = _;
if (sta == 2) {
auto it = lower_bound({3, -1});
if (it != end() && it -> first[1] > len) {
res.emplace_back(array{it -> second, v});
erase(it);
for (it = lower_bound({1, -1}); it != end() && it -> first[0] == 1 && it -> first[1] >= len; erase(it), it = lower_bound({1, -1}));
} else {
auto it = lower_bound({2, -1});
if (it != end() && it -> first[0] == 2 && it -> first[1] >= len) {
erase(it);
}
insert({_, v});
}
} else if (sta == 3) {
auto it = lower_bound({2, -1});
if (it != end() && it -> first[0] == 2 && it -> first[1] < len) {
res.emplace_back(array{it -> second, v});
len = it -> first[1];
erase(it);
for (it = lower_bound({1, -1}); it != end() && it -> first[0] == 1 && it -> first[1] >= len; erase(it), it = lower_bound({1, -1}));
} else {
auto it = lower_bound({3, -1});
if (it != end() && it -> first[1] <= len) {
erase(it);
}
insert({_, v});
}
} else if (sta == 1) {
if (count(_)) {
auto it = find(_);
res.emplace_back(array{it -> second, v});
erase(it);
} else {
insert({_, v});
}
}
}
}
};
vector<array<int, 2>> ans;
auto dsu_tr = [&](auto && self, int u, int fa = 0) -> Info {
Info dp(a[u], dep[u] = dep[fa] + 1, u);
for (auto & v : adj[u]) if (v != fa) {
dp.merge(self(self, v, u), adj[u].size() == 1 + !!fa);
}
ans.insert(ans.end(), dp.res.begin(), dp.res.end());
return move(dp);
};
dsu_tr(dsu_tr, 1);
if (ans.size() * 2 == cnt) {
cout << "YES\n";
} else {
cout << "NO\n";
return;
}
for (auto & [u, v] : ans) {
cout << u << " " << v << "\n";
}
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
// cin >> t;
for (cout << fixed << setprecision(12); t--; QAQ());
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3680kb
input:
8 2 1 - 3 1 - 4 2 Tong 5 2 Tong 6 3 Duan 7 3 - 8 7 Chang
output:
YES 4 5 6 8
result:
ok Correct.
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3700kb
input:
10 2 1 Duan 3 2 Duan 4 2 - 5 4 Chang 6 2 Chang 7 1 Duan 8 6 Tong 9 6 Tong 10 3 Chang
output:
NO
result:
wrong answer Jury has answer but participant has not.