QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#403362#7738. Equivalent RewritingGodwangWA 2ms6140kbC++143.4kb2024-05-02 09:31:342024-05-02 09:31:35

Judging History

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

  • [2024-05-02 09:31:35]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6140kb
  • [2024-05-02 09:31:34]
  • 提交

answer

#include <iostream>
using namespace std;
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <random>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define endl '\n'
const double pai = acos(-1);
ll extend_gcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
ll fastpow(ll a, ll n, ll mod)
{
    ll ans = 1;
    a %= mod;
    while (n)
    {
        if (n & 1)
            ans = (ans * a)%mod; //% mod
        a = (a * a)%mod;         //% mod
        n >>= 1;
    }
    return ans;
}
int dir[4][2] =
    {
        {0, 1}, {0, -1}, {1, 0}, {-1, 0}}; // d a w s

const double inf = 1000000000000000000;
const ll mod = 1e9 + 7, P1 = 13331;
const double eps = 1e-7;
const int N = 1e5 + 10, M = 1e6 + 10;

int t,n,m;
int a[N],d[N];
vector<int > v[N];

int ans[N],cnt;

bool cmp(int x,int y)
{
    return x>y;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   // freopen("ain.txt", "r", stdin);freopen("aout.txt", "w", stdout);
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        fill(a+1,a+n+1,0);
        fill(d+1,d+n+1,0);
        rep(i,1,n)
        {
            v[i].clear();
        }
        rep(i,1,n)
        {
            int p;
            cin>>p;
            while(p--)
            {
                int temp;
                cin>>temp;
                if(a[temp])
                {
                    d[i ]++;
                    v[ a[temp] ].pb(i);
                }
                a[temp]=i;
            }
        }
        cnt=0;
        queue<int > q;
        per(i,1,n)
        {
            if(d[i]==0)
            {
                
                q.push(i);
            }
        }
        while(q.size())
        {
            int u=q.front();
            ans[++cnt]=u;
            q.pop();
            sort(v[u].begin(),v[u].end(),cmp);
            for(auto i:v[u])
            {
                d[i]--;
                if(d[i]==0)
                {
                    q.push(i);
                }
            }
        }
        if(cnt<n)
        {
            cout<<"No"<<endl;
        }
        else
        {
            bool flag=0;
            rep(i,1,n)
            {
                if(ans[i]!=i)
                {
                    flag=1;
                    break;
                }
            }
            if(flag==0)
            {
                cout<<"No"<<endl;
            }
            else
            {
                cout<<"Yes"<<endl;
                
                rep(i,1,n)
                {
                    if(i>1)
                    {
                        cout<<" ";
                    }
                    cout<<ans[i];
                }
                cout<<endl;
            }
        }
        
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6140kb

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: 2ms
memory: 5860kb

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)