QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617814#7738. Equivalent Rewritingxjt05WA 1ms7632kbC++232.4kb2024-10-06 17:14:122024-10-06 17:14:13

Judging History

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

  • [2024-10-06 17:14:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7632kb
  • [2024-10-06 17:14:12]
  • 提交

answer

#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
ll a[200005];
ll b[200005];
ll c[200005];
vector<ll>g[250000];
int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        ll gp = 0;
        ll n, m;
        cin >> m >> n;
        ll temp = 0;
        for (ll i = 1; i <= n; i++)a[i] = 0, c[i] = 0;
        for (ll i = 1; i <= m; i++)b[i] = i, g[i].clear();
        for (ll i = 1; i <= m; i++)
        {
            ll k;
            cin >> k;
            while (k--)
            {
                ll x;
                cin >> x;
                g[i].push_back(x);
                a[i]++;
            }
        }
        ll u = 0, c = 0;
        for (ll i = 1; i <= m; i++)
        {    
            ll z = 0;
            if (c == 0)
            {
                for (auto j : g[i])
                {
                    a[j]--;
                    if (a[j] == 0)
                    {
                        u = i;
                    }
                    else if (a[j] == 1)
                    {
                        u = 0;
                        z = 1;
                    }
                    else
                    {
                        u = i;
                    }
                }
                if (z)
                    c = 0;
                c = u;
            }
            else
            {
                for (auto j : g[i])
                {
                    a[j]--;
                    if (a[j] == 0)
                    {
                        u = i;
                    }
                    else if (a[j] == 1)
                    {
                        u = 0;
                        z = 1;
                    }
                    else
                    {
                        u = i;
                    }
                }
                if (z)
                    u = 0;
                    if (u > 0)
                    {
                        swap(b[c], b[u]);
                        gp = 1;
                        break;
                    } 
            }
        }
        if (gp)
        {
            cout << "Yes" << endl;
            for (ll i = 1; i <= m; i++)
            {
                cout << b[i];
                if (i != m)
                    cout << " ";
            }
            cout << endl;
        }
        else
            cout << "No" << endl;
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7632kb

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
2 1 3
No
No

result:

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