QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#263886 | #7738. Equivalent Rewriting | ucup-team2279# | RE | 0ms | 3588kb | C++14 | 1.4kb | 2023-11-25 09:41:08 | 2023-11-25 09:41:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mk make_pair
#define lowbit(x) (x&(-x))
#define pb emplace_back
#define pr pair<int,int>
#define let const auto
#define all(A) A.begin(),A.end()
void chkmin(int &x,int y){x=min(x,y);}
void chkmax(int &x,int y){x=max(x,y);}
const int N=1e5+5;
int read(){
int x=0,f=1; char c=getchar();
while(('0'>c||c>'9')&&c!='-') c=getchar();
if(c=='-') f=0,c=getchar();
while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return f?x:-x;
}
int main(){
int T=read();
while(T--){
int m=read(),n=read();
vector <vector <int> > adj(m),at(n+1);
vector <int> ind(n+1);
for(int i=0; i<m; i++){
int k=read();
while(k--) at[read()].push_back(i);
}
for(int i=1; i<=n; i++) if(at[i].size())
for(int j=0; j<(int)at[i].size()-1; j++) adj[at[i].back()].push_back(at[i][j]),ind[at[i][j]]++;
priority_queue <int,vector <int>, greater <int> > q;
for(int i=0; i<m; i++) if(!ind[i]) q.emplace(i);
vector <int> ans;
while(!q.empty()){
int x=q.top(); q.pop();
ans.push_back(x);
for(int v:adj[x]) if(!--ind[v]) q.emplace(v);
}
assert((int)ans.size()==m);
reverse(all(ans));
auto chk = [&](){
for(int i=0; i<m; i++) if(ans[i]!=i) return 1;
return 0;
};
if(chk()){
puts("Yes");
for(int i:ans) printf("%d ",i+1);
puts("");
}
else puts("No");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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
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