QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269783 | #7738. Equivalent Rewriting | khoray# | RE | 0ms | 3376kb | C++17 | 1.2kb | 2023-11-29 23:25:19 | 2023-11-29 23:25:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
void solve() {
int m, n; cin >> m >> n;
vector<int> cnt(n + 1);
vector<vector<int>> op(n + 1);
for(int i = 1; i <= m; i++) {
int k; cin >> k;
op[i].resize(k + 1);
for(int j = 1; j <= k; j++) {
cin >> op[i][j];
}
}
for(int i = m; i >= 1; i--) {
int mx = 0;
for(int j = 1; j < op[i].size(); j++) {
int x = op[i][j];
cnt[x]++;
mx = max(cnt[x], mx);
// cerr << "i = " << i << " mx = " << mx << '\n';
}
if(mx == 1 && i < m) {
cout << "Yes\n";
for(int j = 1; j <= m; j++) {
if(j == i) cout << j + 1 << " ";
else if(j == i + 1) cout << i << " ";
else cout << j << " ";
}
cout << '\n';
return;
}
if(i < m) {
for(int j = 1; j < op[i + 1].size(); j++) {
int x = op[i + 1][j];
cnt[x]--;
}
}
}
cout << "No\n";
}
int main() {
cin.tie(0)->sync_with_stdio(false);
int t; cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3376kb
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
Runtime Error
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