QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767721#7738. Equivalent RewritingguangxuautumnRE 0ms0kbC++141.3kb2024-11-20 21:54:172024-11-20 21:54:17

Judging History

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

  • [2024-11-20 21:54:17]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-20 21:54:17]
  • 提交

answer

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

const int N = 1e5+7;
int val[N];
bool vis[N]; 

void solve()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) vis[i] = false;
    vector<vector<int>> b(n+1);
    for (int i = 1; i <= n; ++i)
    {
        int p;
        cin >> p;
        while (p--)
        {
            int x;
            cin >> x;
            b[i].push_back(x);
        }
    }
    
    for (int i = n; i > 1; ++i)
    {
        set<int> s;
        int sz = b[i].size() + b[i-1].size();
        for (auto v : b[i]) 
        {
            if (!vis[v]) s.insert(v);
            else sz--;    
        }
        for (auto v : b[i-1])
        {
            if (!vis[v]) s.insert(v);
            else sz--;
        }
        
        if (s.size() == sz)
        {
            cout << "Yes\n";
            for (int j = 1; j <= n; ++j)
            {
                if (j == i) cout << i-1 << " ";
                else if (j == i-1) cout << i << " ";
                else cout << j << " ";
            }
            cout << "\n";
            return;
        }
        
        for (auto v : b[i]) vis[v] = true;
    }
    
    
    cout << "No\n";
}

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: 0
Runtime Error

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:


result: