QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465893#7738. Equivalent Rewritingevirir#WA 3ms13204kbC++143.0kb2024-07-07 13:03:492024-07-07 13:03:49

Judging History

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

  • [2024-07-07 13:03:49]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13204kb
  • [2024-07-07 13:03:49]
  • 提交

answer

#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 2e5+5;
vector<int>g[MAXN],gr[MAXN];
int out[MAXN];
int main()
{
    owo
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        vii pos(m);
        for(int i=0;i<n;i++){
            g[i].clear();
            gr[i].clear();
            out[i] = 0;
        }
        for(int i=0;i<n;i++){
            int p;
            cin>>p;
            while(p--){
                int x;
                cin>>x;
                pos[x-1].pb(i);
            }
        }
        for(int i=0;i<m;i++){
            for(int j=0;j+1<sz(pos[i]);j++){
                int v = pos[i].back();
                int u = pos[i][j];
                g[v].pb(u);
                gr[u].pb(v);
                //cout<<v<<" "<<u<<'\n';
                out[v]++;
            }
        }
        priority_queue<int>p0;
        for(int i=0;i<n;i++){
            if(!out[i]){
                p0.push(i);
            }
        }
        vector<int>perm(n);
        for(int i=0;i<n;i++){
            int v = p0.top();
            p0.pop();
            perm[v] = i;
            for(int x:gr[v]){
                out[x]--;
                if(!out[x]){
                    p0.push(x);
                }
            }
        }
        bool ok = 0;
        for(int i=0;i<n;i++){
            if(i!=perm[i])ok = 1;
        }
        if(ok){
            cout<<"Yes"<<'\n';
            for(int x:perm)cout<<x+1<<" ";
            cout<<'\n';
            continue;
        }
        priority_queue<int,vector<int>,greater<int>>p1;
        for(int i=0;i<n;i++){
            out[i] = sz(gr[i]);
            if(!out[i])p1.push(i);
        }
        //vector<int>perm(n);
        for(int i=0;i<n;i++){
            int v = p1.top();
            p1.pop();
            perm[v] = i;
            for(int x:gr[v]){
                out[x]--;
                if(!out[x]){
                    p1.push(x);
                }
            }
        }
        if(ok){
            cout<<"Yes"<<'\n';
            for(int x:perm)cout<<x+1<<" ";
            cout<<'\n';
            continue;
        }
        cout<<"No"<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 13204kb

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

result:

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