QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#693627 | #7738. Equivalent Rewriting | konghaojie# | WA | 1ms | 6388kb | C++17 | 1.1kb | 2024-10-31 16:29:15 | 2024-10-31 16:29:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=1e5+5;
vector<int>E[N];
int n,m,c[N]={0};
void Clear(){
for(int i=1;i<=n;i++){
E[i].clear();
}
}
void solve(){
cin>>n>>m;
int a[m+1]={0};
for(int i=1;i<=n;i++){
int k;cin>>k;
set<int>st;
for(int j=0;j<k;j++){
int ind;cin>>ind;
if(a[ind]!=0){
st.insert(a[ind]);
}
a[ind]=i;
}
for(auto it=st.begin();it!=st.end();it++){
E[*it].push_back(i);
c[i]++;
}
}
priority_queue<int>q;
for(int i=1;i<=n;i++){
if(c[i]==0) q.push(i);
}
vector<int>ans;
while(!q.empty()){
int u=q.top();
q.pop();
int len=E[u].size();
ans.push_back(u);
for(int i=0;i<len;i++){
int v=E[u][i];
c[v]--;
if(c[v]==0){
q.push(v);
}
}
}
bool ok=false;
for(int i=0;i<n;i++){
if(ans[i]!=i+1) ok=true;
}
if(ok){
cout<<"Yes"<<endl;
for(int i=0;i<n;i++){
cout<<ans[i]<<" ";
}
cout<<endl;
}else{
cout<<"No"<<endl;
}
Clear();
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6388kb
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: 0ms
memory: 5940kb
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)