QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332999 | #6396. Puzzle: Kusabi | tien_noob | WA | 29ms | 8724kb | C++20 | 2.5kb | 2024-02-19 16:48:16 | 2024-02-19 16:48:16 |
Judging History
answer
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 1e5;
vector<int> adj[N + 1];
string base[] = {"Chang", "Duan", "Tong", "-"};
int a[N + 1], dp[N + 1], n;
int match[N + 1];
void DFS(int u)
{
vector<int> rem[3];
if (a[u] < 3)
{
rem[a[u]].push_back(u);
}
for (int v : adj[u])
{
DFS(v);
if (dp[v])
{
int k = dp[v];
if (a[k] < 2)
{
if (!rem[a[k] ^ 1].empty())
{
match[k] = rem[a[k] ^ 1].back();
rem[a[k] ^ 1].pop_back();
}
else
{
rem[a[k]].push_back(k);
}
}
else
{
if (!rem[2].empty())
{
match[k] = rem[2].back();
rem[2].pop_back();
}
else
{
rem[2].push_back(k);
}
}
}
}
for (int j = 0, sum = 0; j < 3; ++ j)
{
sum += rem[j].size();
if (sum > 1)
{
cout << "NO";
exit(0);
}
if (!rem[j].empty())
{
dp[u] = rem[j].back();
}
}
}
void read()
{
cin >> n;
for (int i = 2; i <= n; ++ i)
{
string s;
int u, v;
cin >> u >> v >> s;
adj[v].push_back(u);
for (int j = 0; j < 4; ++ j)
{
if (s == base[j])
{
a[u] = j;
break;
}
}
//cerr << u << ' ' << a[u] << '\n';
}
}
void solve()
{
a[1] = 3;
DFS(1);
if (dp[1])
{
cout << "NO";
return ;
}
cout << "YES" << '\n';
for (int u = 1; u <= n; ++ u)
{
if (match[u])
{
cout << u << ' ' << match[u] << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
8 2 1 - 3 1 - 4 2 Tong 5 2 Tong 6 3 Duan 7 3 - 8 7 Chang
output:
YES 5 4 8 6
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 1ms
memory: 3828kb
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 5 2 7 6 9 8 10 3
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
2 2 1 Tong
output:
NO
result:
ok Correct.
Test #4:
score: -100
Wrong Answer
time: 29ms
memory: 8724kb
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 106 86 164 93 181 39 204 126 305 237 323 217 339 253 357 17176 381 90406 393 81 433 62 447 435 532 17836 553 326 563 498 591 320 612 418 730 570 758 56513 811 36529 813 550 867 863 879 531 916 59439 973 969 1008 593 1096 1018 1108 575 1124 1056 1164 893 1184 186 1196 473 1259 478 1261 1168 1262 ...
result:
wrong answer Pair 553-326 symbol not satisfied.