QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#560072 | #6396. Puzzle: Kusabi | chimera | WA | 1ms | 5404kb | C++17 | 2.1kb | 2024-09-12 12:00:45 | 2024-09-12 12:00:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
vector<vector<ll>> adj(100000);
vector<char> type(100000, '-');
bool valid = true;
vector<array<ll,2>> out;
vector<tuple<char,ll,ll>> treecur(ll n, ll p, ll d) {
vector<tuple<char,ll,ll>> meeting;
if(type[n] != '-') meeting.push_back({type[n], d, n});
for(auto a: adj[n]) {
if(a != p) {
for(auto x: treecur(a,n,d+1)) meeting.push_back(x);
}
}
if(meeting.size() <= 1) {
return meeting;
}
vector<tuple<char,ll,ll>> tout = {};
map<ll,ll> ts = {};
set<pll> cs;
vector<pll> ds;
for(auto x: meeting) {
char c = get<0>(x);
ll d = get<1>(x), n = get<2>(x);
if(c == 'T') {
if(ts.find(d) == ts.end()) ts[d] = n;
else {
out.push_back({n, ts[d]}); ts.erase(d);
}
}
if(c == 'C') {
cs.insert({d,n});
}
if(c == 'D') ds.push_back({d,n});
}
sort(ds.rbegin(), ds.rend());
for(auto d: ds) {
// match to c with greater depth
auto it = cs.upper_bound({d.first, -1});
if(it == cs.end()) {
tout.push_back({'D',d.first,d.second});
} else {
out.push_back({d.second, (*it).second});
cs.erase(it);
}
}
for(auto c: cs) tout.push_back({'C',c.first,c.second});
for(auto t: ts) tout.push_back({'T',t.first,t.second});
if(tout.size() > 1) {
valid = false;
}
return tout;
}
int main() {
ll N; cin >> N;
for(ll i = 0; i < N-1; i++) {
ll a, b; cin >> a >> b; a--; b--;
adj[a].push_back(b); adj[b].push_back(a);
string S; cin >> S;
type[a]=S[0];
}
treecur(0,-1,0);
if(valid) {
cout << "YES\n";
for(auto xy: out) {
cout << xy[0]+1 << " " << xy[1]+1 << "\n";
}
} else {
cout << "NO\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5276kb
input:
8 2 1 - 3 1 - 4 2 Tong 5 2 Tong 6 3 Duan 7 3 - 8 7 Chang
output:
YES 5 4 6 8
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 1ms
memory: 5404kb
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:
YES 3 10 9 8 2 6 7 5
result:
ok Correct.
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 5288kb
input:
2 2 1 Tong
output:
YES
result:
wrong answer Only odd number of marked vertices to match.