QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117551 | #6396. Puzzle: Kusabi | installb# | WA | 37ms | 29556kb | C++14 | 3.0kb | 2023-07-01 17:04:43 | 2023-07-01 17:04:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
const int N = 200005;
vector <int> G[N],p[3][N];
vector <pair <int,int> > ans;
pair <int,int> q[N]; // <type,id>
int n,dep[N];
int fail = 0;
void dfs(int u){
for(int v : G[u]){
dfs(v);
auto [typ,w] = q[v];
if(w) p[typ][u].push_back(w);
}
for(int i = 0;i < 3;i ++) sort(p[i][u].begin(),p[i][u].end(),[&](int x,int y){ return dep[x] < dep[y]; });
// Tong
q[u] = {-1,0};
for(int i = 0;i < p[2][u].size();i += 2){
if(i + 1 == p[2][u].size() || dep[p[2][u][i]] != dep[p[2][u][i + 1]]){
if(q[u].second) fail = 1;
else{
q[u] = {2,p[2][u][i]};
i --;
}
}
else ans.push_back({p[2][u][i],p[2][u][i + 1]});
}
// Duan == Chang
if(abs((int)(p[0][u].size()) - (int)(p[1][u].size())) >= 2 || (p[0][u].size() != p[1][u].size() && q[u].second)) fail = 1;
if(p[0][u].size() == p[1][u].size()){
for(int i = 0;i < p[0][u].size();i ++){
if(dep[p[0][u][i]] < dep[p[1][u][i]]) ans.push_back({p[0][u][i],p[1][u][i]});
}
}
// Duan < Chang
if(p[0][u].size() + 1 == p[1][u].size()){
int cur = 0;
for(int i = 0;i < p[0][u].size();i ++){
if(cur < p[1][u].size() && dep[p[0][u][i]] < dep[p[1][u][cur]]){
ans.push_back({p[0][u][i],p[1][u][cur]});
cur ++;
}
else{
if(q[u].second) fail = 1;
else{
q[u] = {1,p[1][u][cur]};
cur ++;
}
}
}
if(!q[u].second) q[u] = {1,p[1][u].back()};
}
// Duan > Chang
if(p[1][u].size() + 1 == p[0][u].size()){
int cur = p[0][u].size() - 1;
for(int i = (int)(p[1][u].size()) - 1;i >= 0;i --){
if(cur >= 0 && dep[p[0][u][cur]] < dep[p[1][u][i]]){
ans.push_back({p[0][u][cur],p[1][u][i]});
cur --;
}
else{
if(q[u].second) fail = 1;
else{
q[u] = {0,p[0][u][cur]};
cur --;
}
}
}
if(!q[u].second) q[u] = {0,p[0][u][0]};
}
}
void solve(){
int num = 0;
cin >> n;
dep[1] = 0;
for(int i = 2;i <= n;i ++){
int u,v; string str;
cin >> u >> v >> str;
// u == i
G[v].push_back(u);
dep[u] = dep[v] + 1;
if(str == "Tong") p[2][u].push_back(u),num ++;
if(str == "Duan") p[0][u].push_back(u),num ++;
if(str == "Chang") p[1][u].push_back(u),num ++;
}
dfs(1);
if(fail || (int)(ans.size()) * 2 < num) cout << "NO\n";
else{
cout << "YES\n";
for(auto [u,v] : ans){
cout << u << ' ' << v << '\n';
}
}
}
int main(){
ios::sync_with_stdio(false);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 23104kb
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: 0
Accepted
time: 1ms
memory: 23548kb
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 8 9 2 6 7 5
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 1ms
memory: 23872kb
input:
2 2 1 Tong
output:
NO
result:
ok Correct.
Test #4:
score: -100
Wrong Answer
time: 37ms
memory: 29556kb
input:
100000 2 1 Duan 3 1 Duan 4 3 - 5 4 Duan 6 3 - 7 4 Duan 8 4 - 9 8 - 10 7 Duan 11 9 - 12 7 Duan 13 7 Duan 14 8 Duan 15 13 - 16 10 Duan 17 11 Duan 18 12 - 19 1 Duan 20 5 Duan 21 4 Duan 22 14 Duan 23 16 - 24 22 Duan 25 16 Duan 26 13 - 27 13 - 28 17 - 29 5 Duan 30 22 - 31 23 - 32 9 Duan 33 5 - 34 30 Duan...
output:
NO
result:
wrong answer Jury has answer but participant has not.