QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265352#7738. Equivalent Rewritingucup-team059#WA 1ms3364kbC++201.3kb2023-11-25 17:59:572023-11-25 17:59:57

Judging History

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

  • [2023-11-25 17:59:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3364kb
  • [2023-11-25 17:59:57]
  • 提交

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 and 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: 0
Wrong Answer
time: 1ms
memory: 3364kb

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
Yes
1 2
Yes
1

result:

wrong answer two transactions are same. (test case 2)