QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243310#7738. Equivalent Rewritingucup-team1769WA 1ms6120kbC++201.7kb2023-11-08 01:58:462023-11-08 01:58:46

Judging History

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

  • [2023-11-08 01:58:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6120kb
  • [2023-11-08 01:58:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
#define endl '\n'
const int mod = 998244353;
const int N = 1e5 + 10;
const int M = 1e5 + 10;

vector<int> g[N];
int in[N];

void solve()
{

    int n, m;
    cin >> n >> m;
    for (int i = 0; i <= m; i++)
    {
        g[i].clear();
    }
    vector<int> v(m + 10);
    for (int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            int x;
            cin >> x;
            if (v[x])
            {
                g[v[x]].push_back(i);
                in[i]++;
            }
            v[x] = i;
        }
    }

    queue<int> q;
    for (int i = n; i >= 1; i--)
    {
        if (in[i] == 0)
            q.push(i);
    }

    vector<int> ans;
    while (!q.empty())
    {
        int now = q.front();
        q.pop();
        ans.push_back(now);
        for (auto it : g[now])
        {
            in[it]--;
            if (in[it] == 0)
                q.push(it);
        }
    }

    bool flag = 0;
    for (int i = 0; i < ans.size(); i++)
    {
        if (ans[i] != i + 1)
        {
            flag = 1;
            break;
        }
    }

    if (!flag)
        cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
        for (int i = 0; i < ans.size(); i++)
        {
            if (i)
                cout << ' ';
            cout << ans[i];
        }
        cout << endl;
    }
}

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

    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 6120kb

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)