QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#263886#7738. Equivalent Rewritingucup-team2279#RE 0ms3588kbC++141.4kb2023-11-25 09:41:082023-11-25 09:41:08

Judging History

你现在查看的是最新测评结果

  • [2023-11-25 09:41:08]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3588kb
  • [2023-11-25 09:41:08]
  • 提交

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

output:


result: