QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408363#6396. Puzzle: KusabiRico64WA 4ms16076kbC++231.8kb2024-05-10 08:04:582024-05-10 08:05:00

Judging History

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

  • [2024-05-10 08:05:00]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:16076kb
  • [2024-05-10 08:04:58]
  • 提交

answer

#include <iostream>
#include <vector>
#include <list>

const int MAX_N = 100000;

using namespace std;

int n;
string val[MAX_N];
vector<int> graph[MAX_N];
list<int> tong[MAX_N], duan[MAX_N], chang[MAX_N];

void search1(int v, int p, int l) {
    if (val[v] == "Duan") {
        duan[l].push_back(v);
    } else if (val[v] == "Tong") {
        tong[l].push_back(v);
    } else if (val[v] == "Chang") {
        chang[l].push_back(v);
    }
    for (const int& ne : graph[v]) {
        if (ne == p) continue;
        search1(ne, v, l + 1);
    }
}

int main() {
    cin >> n;
    for (int i = 1, f, t; i < n; ++i) {
        cin >> f >> t;
        f--; t--;
        cin >> val[f];
        graph[f].push_back(t);
        graph[t].push_back(f);
    }
    search1(0, -1, 0);
    vector<pair<int,int>> res;
    list<int> duans;
    for (int l = 0; l < n; ++l) {
        while (!chang[l].empty() && !duans.empty()) {
            res.push_back({chang[l].front(), duans.front()});
            chang[l].pop_front();
            duans.pop_front();
        }
        if (!chang[l].empty()) {
            cout << "NO" << endl;
            return 0;
        }
        while (tong[l].size() >= 2) {
            int f = tong[l].front(); tong[l].pop_front();
            int t = tong[l].front(); tong[l].pop_front();
            res.push_back({f, t});
        }
        if (!tong[l].empty()) {
            cout << "NO" << endl;
            return 0;
        }
        while (!duan[l].empty()) {
            int v = duan[l].front(); duan[l].pop_front();
            duans.push_back(v);
        }
    }
    if (!duans.empty()) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    for (const auto& r : res) {
        cout << r.first + 1 << ' ' << r.second + 1 << endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 16076kb

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: -100
Wrong Answer
time: 4ms
memory: 16072kb

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
6 2
10 7
5 3
8 9

result:

wrong answer Edge 3-2 used twice.