QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#266465#7738. Equivalent Rewritingucup-team059WA 0ms3380kbC++201.3kb2023-11-26 14:26:222023-11-26 14:26:22

Judging History

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

  • [2023-11-26 14:26:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3380kb
  • [2023-11-26 14:26:22]
  • 提交

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), op(n + 1);
    for (int i = 1, p; i <= n; i++) {
        cin >> p;
        for (int x; p; p--)
            cin >> x, op[i].push_back(x), lst[x] = i;
    }

    for (int i = 1; i <= n; i++) {
        for (int j; auto t: op[i]) {
            j = lst[t];
            if (i == j) continue;
            e[i].push_back(j), inDeg[j]++;
        }
    }

    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]) {
            inDeg[v]--;
            if (inDeg[v] == 0) res.push_back(v);
        }
    }
    if (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: 3368kb

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

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:

Yes
8 7 6 5 4 3 2 1 9

result:

wrong output format Unexpected end of file - int32 expected (test case 1)