QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692707 | #7738. Equivalent Rewriting | travel | WA | 4ms | 8520kb | C++14 | 1.7kb | 2024-10-31 14:56:18 | 2024-10-31 14:56:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> PII;
#define endl "\n"
#define ft first
#define sd second
#define pb push_back
const int MOD = 1e9 + 7,N = 1e5 + 10;
set<int,greater<int>> e[N];
int d[N];
void solve() {
int n,m; cin>>n>>m;
map<int,int> mp;
for(int i = 1;i <= n;i++)
{
d[i] = 0;
e[i].clear();
}
map<PII,int> edge;
for(int i = 1;i <= n;i++){
int x; cin>>x;
for(int j = 1;j <= x;j++){
int y; cin>>y;
if(mp.count(y) && !edge.count({mp[y],i})){
e[mp[y]].insert(i);
edge[{mp[y],i}] = 1;
d[i]++;
}
else mp[y] = i;
}
}
queue<int> q;
for(int i = 1;i <= n;i++)
if(!d[i]) q.push(i);
vector<int> ans;
while(q.size()){
int t = q.front(); q.pop();
ans.pb(t);
for(int v : e[t]){
if(--d[v] == 0)
q.push(v);
}
}
int cnt = 1,flag = 0;
for(int x : ans){
if(x != cnt++)
{
flag = 1;
break;
}
}
if(!flag) cout<<"No\n";
else {
cout<<"Yes\n";
for(int x : ans)
cout<<x<<' ';
cout<<endl;
}
return ;
}
signed main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int T = 1;
cin>>T;
while(T--)
solve();
return 0;
}
/*
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
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
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8520kb
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
Wrong Answer
time: 4ms
memory: 8300kb
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 1 10 2 5 4 3 7 6 9 8
result:
wrong answer two transactions are not equivalent. (test case 1)