QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403377 | #7738. Equivalent Rewriting | Godwang | WA | 0ms | 8308kb | C++14 | 4.8kb | 2024-05-02 10:01:35 | 2024-05-02 10:01:36 |
Judging History
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],w[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+m+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;
w[temp].pb(i);
}
}
rep(i,1,m)
{
int siz=w[i].size();
if(siz<=1)
{
continue;
}
int mowei=w[i][siz-1];
for(auto j:w[i])
{
if(j!=mowei)
{
d[mowei]++;
v[j].pb(mowei);
}
}
}
bool flag=0;
rep(i,1,n-1)
{
bool ok=1;
for(auto j:v[i])
{
if(j==i+1)
{
ok=0;
break;
}
}
if(ok==1)
{
flag=1;
cout<<"Yes"<<endl;
rep(j,1,n)
{
if(j>1)
{
cout<<" ";
}
if(j==i)
{
cout<<j+1;
}
else if(j==i+1)
{
cout<<j-1;
}
else
{
cout<<j;
}
}
cout<<endl;
}
}
if(flag==0)
cout<<"No"<<endl;
}
// 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: 0ms
memory: 8292kb
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 1 3 2 No No
result:
ok OK. (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 8308kb
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:
Yes 2 1 3 4 5 6 7 8 9 10 Yes 1 3 2 4 5 6 7 8 9 10 Yes 1 2 4 3 5 6 7 8 9 10 Yes 1 2 3 5 4 6 7 8 9 10 Yes 1 2 3 4 6 5 7 8 9 10 Yes 1 2 3 4 5 7 6 8 9 10 Yes 1 2 3 4 5 6 8 7 9 10
result:
wrong output format Extra information in the output file (test case 1)