QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#275330#7738. Equivalent RewritingDateTreeWA 0ms3804kbC++171.4kb2023-12-04 16:48:402023-12-04 16:48:40

Judging History

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

  • [2023-12-04 16:48:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2023-12-04 16:48:40]
  • 提交

answer

#include <bits/stdc++.h>

bool chk(std::vector<int>& a) {
    int n = a.size();
    for (int i = 0; i < n; ++i)
        if (a[i] != i + 1)
            return 0;
    return 1;
}

int main() {
    //freopen("in", "r", stdin);
    int ttt;
    std::cin >> ttt;
    while (ttt--) {
        int n, m;
        std::cin >> n >> m;
        std::vector<int> b(m + 1), ind(n + 1);
        std::vector ver(n + 1, std::vector<int>(0));
        for (int i = 1; i <= n; ++i) {
            int p, x;
            std::cin >> p;
            while (p--) {
                std::cin >> x;
                if (b[x]) {
                    ver[b[x]].push_back(i);
                    ++ind[i];
                }
                b[x] = i;
            }
        }
        std::queue<int> q;
        std::vector<int> ans;
        for (int i = n; i >= 1; --i) {
            if (!ind[i]) {
                q.push(i);
            }
        }
        while (!q.empty()) {
            int u = q.front(); q.pop();
            ans.emplace_back(u);
            for (auto &v: ver[u]) {
                --ind[v];
                if (!ind[v])
                    q.push(v);
            }
        }
        if (chk(ans)) {
            std::cout << "No\n";
            continue;
        }
        std::cout << "Yes\n";
        for (int i = 0; i < n; ++i)
            std::cout << ans[i] << " \n"[i == n - 1];
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 6
3 3 1 5
2 5 3
2 2 6
2 3
3 1 3 2
2 3 1
1 3
2 2 1

output:

Yes
3 1 2
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3804kb

input:

1
10 5
2 2 4
4 1 3 4 2
1 2
3 2 1 4
4 5 2 4 3
3 2 5 4
3 5 4 2
3 1 3 2
5 1 4 2 3 5
1 4

output:

No

result:

wrong answer jury found an answer but participant did not (test case 1)