QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#332991#6396. Puzzle: Kusabitien_noobWA 1ms3548kbC++202.4kb2024-02-19 16:46:352024-02-19 16:46:36

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 16:46:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3548kb
  • [2024-02-19 16:46:35]
  • 提交

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);
    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: 0
Wrong Answer
time: 1ms
memory: 3548kb

input:

8
2 1 -
3 1 -
4 2 Tong
5 2 Tong
6 3 Duan
7 3 -
8 7 Chang

output:

NO

result:

wrong answer Jury has answer but participant has not.