QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642988#7738. Equivalent RewritingKDreamWA 0ms3624kbC++201.8kb2024-10-15 17:32:342024-10-15 17:32:35

Judging History

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

  • [2024-10-15 17:32:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-10-15 17:32:34]
  • 提交

answer

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

void Z()
{
    int n, m;
    cin >> n >> m;
    int y = max(n, m);
    vector<vector<int>> a(y + 5), edge(y + 5);
    for (int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        while (x--)
        {
            int b;
            cin >> b;
            a[b].push_back(i);
        }
    }
    vector<int> in(y + 5);
    for (int i = 1; i <= m; i++)
    {
        if (a[i].size() == 0)
            continue;

        int go = a[i].back();
        for (auto v : a[i])
        {
            if (v == go)
                continue;

            edge[v].push_back(go);
            in[go]++;
        }
    }
    queue<int> q;
    vector<int> ans;
    ans.push_back(0);
    for (int i = n; i >= 1; i--)
    {
        if (!in[i])
        {
            q.push(i);
        }
    }
    while (!q.empty())
    {
        auto u = q.front();
        q.pop();
        ans.push_back(u);

        if (edge[u].size())
            sort(edge[u].begin(), edge[u].end(), greater<>());

        for (auto v : edge[u])
        {
            in[v]--;
            if (!in[v])
            {
                q.push(v);
            }
        }
    }
    bool flag = 1;
    for (int i = 1; i <= ans.size(); i++)
    {
        if (i != ans[i])
        {
            flag = 0;
            break;
        }
    }

    if (flag)
    {
        cout << "No";
    }
    else
    {
        cout << "Yes\n";
        for (int i = 1; i <= n; i++)
        {
            cout << ans[i] << " ";
        }
    }
}

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

    int t = 1;
    cin >> t;
    while (t--)
    {
        Z();
        if (t)
        {
            cout << "\n";
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3624kb

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)