QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265275 | #7738. Equivalent Rewriting | ucup-team191# | WA | 3ms | 20744kb | C++14 | 1.8kb | 2023-11-25 17:37:21 | 2023-11-25 17:37:22 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)
const int MAXN=300010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;
int t, n, m;
int a[MAXN], clash[MAXN], covered[MAXN];
vector <int> v[MAXN], r[MAXN], sol;
set <int> st;
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
a[i] = 0;
covered[i] = 0;
r[i].clear();
}
for (int i = 1; i <= n; i++) {
v[i].clear();
clash[i] = 0;
int len;
cin >> len;
for (int j = 1; j <= len; j++) {
int x;
cin >> x;
v[i].push_back(x);
a[x] = j;
}
}
st.clear();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= (int)v[i].size(); j++) {
int idx = v[i][j - 1];
if (a[idx] != j) {
clash[i]++;
r[idx].push_back(i);
}
}
if (clash[i] == 0) st.insert(i);
}
sol.clear();
while (!st.empty()) {
int i = *st.begin();
st.erase(st.begin());
sol.push_back(i);
for (int j = 1; j <= (int)v[i].size(); j++) {
int idx = v[i][j - 1];
if (covered[idx] == 0) {
for (auto k : r[idx]) {
clash[k]--;
if (clash[k] == 0) {
st.insert(k);
}
}
}
covered[idx] = 1;
}
}
reverse(sol.begin(), sol.end());
bool ok = 0;
for (int i = 1; i <= n; i++) {
if (i != sol[i - 1]) ok = 1;
}
if (ok) {
cout << "Yes\n";
for (int i = 1; i <= n; i++) {
cout << sol[i - 1];
if (i < n) cout << " ";
}
cout << '\n';
} else {
cout << "No\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 20572kb
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 No
result:
ok OK. (3 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 20032kb
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 8 7 6 5 4 3 2 1 9 10
result:
ok OK. (1 test case)
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 20744kb
input:
1 20 5 5 4 1 2 5 3 2 5 3 3 5 1 2 5 4 5 1 3 2 3 4 2 5 5 3 1 5 4 2 5 5 1 2 3 4 1 3 4 5 1 2 3 4 4 1 3 5 2 5 2 4 2 3 5 1 3 2 4 5 5 2 3 4 1 5 4 5 2 4 3 1 2 2 4 3 4 4 5 3 1 5 4 1 5 3 2 3 5 1 3
output:
Yes 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 3 1 4 2 20
result:
wrong answer two transactions are not equivalent. (test case 1)