QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267843 | #7738. Equivalent Rewriting | Nanfeng1997 | WA | 1ms | 3384kb | C++14 | 2.4kb | 2023-11-27 19:30:48 | 2023-11-27 19:30:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n, m; cin >> n >> m;
vector<vector<int> > a(n);
vector<int> cnt(m + 1), ncnt(m + 1);
for (int i = 0; i < n; i ++ ) {
int x; cin >> x;
a[i].resize(x);
for (int j = 0; j < x; j ++ ) {
cin >> a[i][j];
cnt[a[i][j]] += 1;
}
}
for (int i = 0; i < n; i ++ ) {
bool f = true;
for (int j = 0; j < a[i].size() and f; j ++ ) {
if (cnt[a[i][j]] != 1) {
f = false;
}
}
if (f) {
cout << "Yes\n";
vector<int> ans;
if (!i) {
for (int j = 0; j < n; j ++ ) if (j != i) {
ans.push_back(j + 1);
}
ans.push_back(i + 1);
} else {
ans.push_back(i + 1);
for (int j = 0; j < n; j ++ ) if (j != i) {
ans.push_back(j + 1);
}
}
for (int &x: ans) cout << x << " \n"[x == ans.back()];
return;
}
}
map<int, int> mp;
for (int &x: a[0]) mp[x] += 1;
for (int i = 1; i < n; i ++ ) {
bool f = true;
for (int &x: a[i]) {
if (mp[x]) f = false;
mp[x] += 1;
}
if (f) {
cout << "Yes\n";
vector<int> ans;
for (int j = 0; j < i - 1; j ++ ) {
ans.push_back(j + 1);
}
ans.push_back(i + 1);
ans.push_back(i);
for (int j = i + 1; j < n; j ++ ) {
ans.push_back(j + 1);
}
for (int &x: ans) cout << x << " \n"[x == ans.back()];
return;
}
for (int x: a[i - 1]) {
mp[x] -= 1;
}
}
for (int x: a[0]) ncnt[x] += 1;
for (int i = 1; i < n; i ++ ) {
bool f = true;
for (int &x: a[i]) {
if (!f) break;
if (ncnt[x] == 0) continue; //前面没有
if (ncnt[x] + 1 != cnt[x]) continue; //前面有,但我不是最后一个
f = false;
}
if (f) {
cout << "Yes\n";
vector<int> ans;
for (int j = 0; j < i - 1; j ++ ) {
ans.push_back(j + 1);
}
ans.push_back(i + 1);
ans.push_back(i);
for (int j = i + 1; j < n; j ++ ) {
ans.push_back(j + 1);
}
for (int &x: ans) cout << x << " \n"[x == ans.back()];
return;
}
for (int &x: a[i]) ncnt[x] += 1;
}
cout << "No\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while (T -- )
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3384kb
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 Yes 1
result:
wrong answer two transactions are same. (test case 3)