RE 0pts 但过了 hack?
  • 板块P1347 排序
  • 楼主Hero_Broom
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/4/5 21:35
  • 上次更新2024/4/6 06:12:06
查看原帖
RE 0pts 但过了 hack?
970132
Hero_Broom楼主2024/4/5 21:35

https://www.luogu.com.cn/record/154485842

测试数据下载下来本地运行AC,但交上去RE。

#include<bits/stdc++.h>
using namespace std;
int n,m,graph[10010][10010],degree[10010],now[10010];//degree:入度
bool b[10010];
string ans;
int top(){
	ans="";
	int f=1;
	for(int i=1;i<=n;i++) now[i]=degree[i],b[i]=0;
	for(int o=0;o<n;o++){
		int cnt=0,minpos;
		for(int i=1;i<=n;i++)
			if(b[i]==0&&now[i]==0) cnt++,minpos=i;
		if(cnt==0) return -1;
		if(cnt>=2) f=0;
		ans+=minpos+64;
		b[minpos]=1;
		for(int j=1;j<=n;j++)
			if(graph[minpos][j]==1)
				now[j]--;
	}
	return f;
}
int main(){
	scanf("%d%d",&n,&m);
	getchar();
	for(int i=1;i<=26;i++){
		for(int j=1;j<=26;j++)
			graph[i][j]=0;
		degree[i]=0;
	}
	int flag=0;
	for(int i=1;i<=m;i++){
		string tmp;
		getline(cin,tmp);
		char t1=tmp[0]-64,t2=tmp[tmp.size()-1]-64;
		if(graph[t1][t2]==0) degree[t2]++;
		graph[t1][t2]=1;
		int p=top();
		if(flag==0){
			if(p==1){
				printf("Sorted sequence determined after %d relations: ",i);
				cout<<ans<<".\n";
				flag=1;
			}else if(p==-1) printf("Inconsistency found after %d relations.\n",i),flag=1;
		}
	}
	if(!flag) printf("Sorted sequence cannot be determined.\n");
}
2024/4/5 21:35
加载中...