QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262991#7738. Equivalent Rewritingucup-team093#WA 0ms3816kbC++171.3kb2023-11-24 13:55:152023-11-24 13:55:15

Judging History

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

  • [2023-11-24 13:55:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2023-11-24 13:55:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > g(n), a(m);
    vector<int> deg(n);
    for(int i = 0, p; i < n; i ++) {
        cin >> p;
        for(int j = 0, x; j < p; j ++) {
            cin >> x;
            a[x - 1].push_back(i);
        }
    }
    
    for(int i = 0; i < m; i ++) {
        if(a[i].size() > 1) {
            for(int j = 0; j + 1 < a[i].size(); j ++)
                g[a[i][j]].push_back(a[i].back());
                deg[a[i].back()] ++;
        }
    }

    priority_queue<int> q;
    for(int i = 0; i < n; i ++)
        if(deg[i] == 0)
            q.push(i);
    
    vector<int> ans;
    while(q.size()) {
        int u = q.top();
        q.pop();
        ans.push_back(u);
        for(auto v : g[u]) {
            if(--deg[v] == 0)
                q.push(v);
        }
    }
    for(int i = 0; i < n; i ++)
        if(ans[i] != i) {
            cout << "Yes\n";
            for(auto x : ans)
                cout << x + 1 << " \n"[x == ans.back()];
            return;
        }
    cout << "No\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T --)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

wrong answer two transactions are not equivalent. (test case 1)