QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265356#7738. Equivalent Rewritingucup-team059WA 0ms3632kbC++201.3kb2023-11-25 18:00:302023-11-25 18:00:30

Judging History

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

  • [2023-11-25 18:00:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2023-11-25 18:00:30]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define int long long

using i64 = long long;
using i32 = int32_t;
using vi = vector<int>;
using pii = pair<int, int>;

const int N = 1e4 + 5;

void solve() {
    int n, m;
    cin >> n >> m;
    vi lst(m + 1), inDeg(n + 1);
    vector<vi> e(n + 1);
    for (int i = 1, p; i <= n; i++) {
        cin >> p;
        for (int x; p; p--) {
            cin >> x;
            if (lst[x] != 0 and lst[x] != i ) {
                inDeg[i]++;
                e[lst[x]].push_back(i);
            }
            lst[x] = i;
        }
    }
    priority_queue<int> q;
    for (int i = 1; i <= n; i++)
        if (inDeg[i] == 0) q.push(i);
    vi res;
    for (int u; not q.empty();) {
        u = q.top(), q.pop();
        res.push_back(u);
        for (auto v: e[u]) {
            if (--inDeg[v] == 0) res.push_back(v);
        }
    }
    if (res.size() != n or is_sorted(res.begin(), res.end())) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (auto i: res)
            cout << i << " \n"[i == res.back()];
    }
    return;
}

i32 main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    i32 TC;
    for (cin >> TC; TC; TC--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3620kb

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)