QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528432 | #6396. Puzzle: Kusabi | hnust_xiaoqi# | WA | 14ms | 12444kb | C++20 | 1.5kb | 2024-08-23 14:01:43 | 2024-08-23 14:01:43 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int N = 2e5 + 10;
typedef long long LL;
pair<LL,LL> duan[N],chang[N],tong[N];
LL h[N];
LL n;
LL inde_duan,inde_chang,inde_tong;
bool check(){
if(inde_chang!=inde_duan||(inde_tong&1)) return false;
for(LL i=1;i<=inde_tong;i+=2){
if(tong[i].second!=tong[i+1].second){
return false;
}
}
for(LL i=1;i<=inde_duan;++i){
if(duan[i].second>=chang[i].second){
return false;
}
}
return true;
}
void solve() {
cin >> n;
for(int i = 1; i < n; i++) {
LL data,data2;
string str;
cin>>data>>data2>>str;
h[data]=h[data2]+1;
if(str[0]=='T'){
tong[++inde_tong]={data,h[data]};
}else if(str[0]=='C'){
chang[++inde_chang]={data,h[data]};
}else if(str[0]=='D'){
duan[++inde_duan]={data,h[data]};
}
}
sort(tong+1,tong+inde_tong+1,[&](const auto& a,const auto &b){
return a.second<b.second;
});
sort(duan+1,duan+inde_duan+1,[&](const auto& a,const auto &b){
return a.second<b.second;
});
sort(chang+1,chang+inde_chang+1,[&](const auto& a,const auto &b){
return a.second<b.second;
});
if(check()){
cout<<"YES"<<endl;
for(LL i=1;i<=inde_tong;i+=2){
cout<<tong[i].first<<' '<<tong[i+1].first<<endl;
}
for(LL i=1;i<=inde_duan;++i){
cout<<duan[i].first<<' '<<chang[i].first<<endl;
}
}else{
cout<<"NO"<<endl;
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9704kb
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: 9752kb
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 8 9 2 6 7 5 3 10
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 0ms
memory: 5664kb
input:
2 2 1 Tong
output:
NO
result:
ok Correct.
Test #4:
score: -100
Wrong Answer
time: 14ms
memory: 12444kb
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:
YES 78961 61327 79617 28763 3283 78400 8241 93895 28194 69010 59851 85932 52589 27446 31315 7241 69894 83333 58699 33789 15911 19874 3681 24772 41090 95031 8873 3156 79799 14132 87751 74813 28273 85594 53651 61413 27407 11158 61255 27084 2042 86323 60707 54276 41654 35332 8051 63173 35912 79826 5203...
result:
wrong answer Edge 4707-66 used twice.