QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#633451 | #7738. Equivalent Rewriting | CUHK_723 | WA | 3ms | 9716kb | C++14 | 2.2kb | 2024-10-12 15:25:01 | 2024-10-12 15:25:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
char ch = getchar();
while(ch < '0' || ch > '9') {
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x;
}
int T, n, m;
int a[100010], in[100010], out[100010], arga[100010];
vector<int> f[100010], e[100010];
void solve() {
if(m == 1) {
cout << "No";
return;
}
queue<int> s;
for(int i = 1; i <= n; ++i) {
if(f[i].size() <= 1) continue;
for(int j = 1; j < f[i].size(); ++j) {
int x = f[i][j], y = f[i][j - 1];
swap(x, y);
e[x].push_back(y);
in[y] += 1;
out[x] += 1;
}
}
int num = 0;
queue<int> q;
for(int i = 1; i <= m; ++i) {
if(in[i] == 0 && out[i] == 0) {
s.push(i);
num += 1;
continue;
}
if(in[i] == 0) q.push(i);
}
num = m - num;
int ans = 0;
while(!q.empty()) {
int x = q.front();
q.pop();
ans += 1;
arga[ans] = x;
//cout << e[x].size() << endl;
for(int i = 0; i < e[x].size(); ++i) {
int y = e[x][i];
in[y] -= 1;
if(in[y] == 0) q.push(y);
}
}
if(num < m && num == ans) {
cout << "Yes" << endl;
int op = 0;
if(s.front() == 1) {
s.pop();
op = 1;
}
while(!s.empty()) {
cout << s.front() << " ";
s.pop();
}
for(int i = 1; i < ans; ++i) cout << arga[i] << " ";
cout << arga[num];
if(op == 1) {
cout << " " << 1 << endl;
}
else cout << endl;
}
else if(num != ans) {
cout << "No" << endl;
}
else {
for(int i = 1; i <= num; ++i) {
if(arga[i] != i) {
break;
}
if(i == num) {
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
for(int i = 1; i < num; ++i) {
cout << arga[i] << " ";
}
cout << arga[num] << endl;
}
}
int main() {
T = read();
while(T) {
T -= 1;
m = read();
n = read();
int num, x;
for(int i = 1; i <= n; ++i) {
arga[i] = 0;
in[i] = 0;
out[i] = 0;
a[i] = 0;
f[i].clear();
e[i].clear();
}
for(int i = 1; i <= m; ++i) {
num = read();
for(int j = 1; j <= num; ++j) {
x = read();
a[x] = i;
f[x].push_back(i);
}
}
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8336kb
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: -100
Wrong Answer
time: 3ms
memory: 9716kb
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:
No
result:
wrong answer jury found an answer but participant did not (test case 1)