QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#105174 | #6396. Puzzle: Kusabi | Sommohito# | WA | 32ms | 8124kb | C++20 | 4.0kb | 2023-05-13 15:25:21 | 2023-05-13 15:25:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef APURBA
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define ALL(x) x.begin(),x.end()
const int N = 1e5 +5;
typedef pair<int,int> pii;
int n;
vector<int>adj[N];
int par[N];
int typ[N];
map<string,int>mp;
vector<pii>ans;
void no()
{
cout<<"NO\n";
exit(0);
}
vector<int> dfs(int s)
{
vector<pii>all[4];
for(auto u:adj[s])
{
vector<int>cur = dfs(u);
if(cur.size())
{
assert(cur.size()==3);
all[cur[0]].push_back({cur[1],cur[2]+1});
}
}
if(typ[s]!=0)
all[typ[s]].push_back({s,0});
for(int i=1; i<=3; i++)
sort(all[i].begin(),all[i].end());
vector<int> jabe ;
{
int p1 = (int)all[1].size() - 1;
int p2 = (int)all[2].size() - 1;
while(1)
{
if(p1 < 0 && p2 < 0)
break;
if(p1 < 0)
{
if(jabe.size())
{
no();
}
else
{
jabe = {2,all[2][p2].first,all[2][p2].second};
}
p2--;
}
else if(p2 < 0)
{
if(jabe.size())
{
no();
}
else
{
jabe = {1,all[1][p1].first,all[1][p1].second};
}
p1--;
}
else
{
if(all[1][p1].second > all[2][p2].second)
{
ans.push_back({all[1][p1].first,all[2][p2].first});
p1--;
p2--;
}
else
{
if(all[1].size() > all[2].size())
{
if(jabe.size())
{
no();
}
else
{
jabe = {1,all[1][p1].first,all[1][p1].second};
}
p1--;
}
else
{
if(jabe.size())
{
no();
}
else
{
jabe = {2,all[2][p2].first,all[2][p2].second};
}
p2--;
}
}
}
}
}
{
map<int,vector<int> >mp;
for(auto it:all[3])
{
mp[it.second].push_back(it.first);
}
for(auto it:mp)
{
vector<int>tmp = it.second;
if(tmp.size()%2)
{
if(jabe.size())
no();
else
{
jabe ={3, tmp.back(), it.first};
tmp.pop_back();
}
}
for(int i=1;i<tmp.size();i+=2)
{
ans.push_back({tmp[i-1],tmp[i]});
}
}
}
return jabe;
}
int32_t main()
{
#ifndef APURBA
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
mp["Chang"] = 1;
mp["Duan"] = 2;
mp["Tong"] = 3;
mp["-"] = 0;
cin>>n;
for(int i=0; i<n-1; i++)
{
int u,v;
cin>>u>>v;
u--;
v--;
par[u] = v;
adj[v].push_back(u);
string s;
cin>>s;
assert(mp.count(s));
typ[u] = mp[s];
}
vector<int> lol = dfs(0);
if(lol.size())
{
cout<<"NO\n";
return 0;
}
cout<<"YES\n";
for(auto it:ans)
cout<<it.first+1<<" "<<it.second+1<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 5792kb
input:
8 2 1 - 3 1 - 4 2 Tong 5 2 Tong 6 3 Duan 7 3 - 8 7 Chang
output:
YES 4 5 8 6
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 2ms
memory: 6180kb
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 10 3 8 9 6 2 5 7
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 2ms
memory: 5740kb
input:
2 2 1 Tong
output:
NO
result:
ok Correct.
Test #4:
score: -100
Wrong Answer
time: 32ms
memory: 8124kb
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.