divccc

Created Diff never expires
2 removals
94 lines
2 additions
94 lines
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using namespace std;
#define int long long
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pb push_back
#define pii pair<int, int>
#define pii pair<int, int>
#define ff first
#define ff first
#define ss second
#define ss second
#define PI acos(-1)
#define PI acos(-1)
#define ld long double
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N], n, m, k;
int a[N], n, m, k;
int b[N];
int b[N];
void solve(int test_case){
void solve(int test_case){
int i, j;
int i, j;
cin >> n >> m;
cin >> n >> m;
for(i=1;i<=n;i++)cin >> a[i];
for(i=1;i<=n;i++)cin >> a[i];
for(i=1;i<=n;i++)cin >> b[i];
for(i=1;i<=n;i++)cin >> b[i];
vector<vector<int>> mp(n+1);
vector<vector<int>> mp(n+1);
vector<int> ind(n+1,0);
vector<int> ind(n+1,0);
vector<bool> used(n+1,0);
vector<bool> used(n+1,0);
for(i=1;i<=n;i++){
for(i=1;i<=n;i++){
if(a[i] != b[i]){
if(a[i] != b[i]){
used[i] = true;
used[i] = true;
mp[b[i]].pb(i);
mp[b[i]].pb(i);
}
}
}
}
for(i=1;i<=n;i++){
for(i=1;i<=n;i++){
if(used[i])continue;
if(used[i])continue;
mp[b[i]].pb(i);
mp[b[i]].pb(i);
}
}
vector<int> ans(m+1);
vector<int> ans(m+1);
vector<int> cc(m+1);
vector<int> cc(m+1);
for(i=1;i<=m;i++){
for(i=1;i<=m;i++){
cin >> cc[i];
cin >> cc[i];
}
}
for(i=1;i<=m;i++){
for(i=1;i<=m;i++){
int x = cc[i];
int x = cc[i];
if(mp[x].empty()){
if(mp[x].empty()){
continue;
continue;
}
}
int now = mp[x][ind[x]];
int now = mp[x][ind[x]];
ans[i] = now;
ans[i] = now;
a[now] = x;
a[now] = x;
ind[x]++;
ind[x]++;
ind[x] %= mp[x].size();
ind[x] %= mp[x].size();
}
}
vector<int> rem;
vector<int> rem;
for(i=m;i>=1;i--){
for(i=m;i>=1;i--){
if(ans[i] == 0){
if(ans[i] == 0){
if(rem.empty()){
if(rem.empty()){
cout << "NO\n";
cout << "NO\n";
return;
return;
}
}
int t = rem.back();//rem.pop_back();
int t = rem.back();//rem.pop_back();
ans[i] = t;
ans[i] = t;
}else {
}else {
rem.pb(ans[i]);
rem.pb(ans[i]);
}
}
}
}
for(i=1;i<=m;i++){
for(i=1;i<=n;i++){
if(a[i] != b[i]){
if(a[i] != b[i]){
cout << "NO\n";
cout << "NO\n";
return;
return;
}
}
}
}
for(i=1;i<=m;i++)assert(ans[i]);
cout << "YES\n";
cout << "YES\n";
for(i=1;i<=m;i++)cout << ans[i] << ' ';
for(i=1;i<=m;i++)cout << ans[i] << ' ';
cout << '\n';
cout << '\n';
return;
return;
}
}


signed main(){
signed main(){
FASTIO;
FASTIO;
#define MULTITEST 1
#define MULTITEST 1
#if MULTITEST
#if MULTITEST
int _T;
int _T;
cin >> _T;
cin >> _T;
for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
solve(T_CASE);
solve(T_CASE);
#else
#else
solve(1);
solve(1);
#endif
#endif
return 0;
return 0;
}
}