QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#302279#4829. Mark on a GraphLoging#0 0ms0kbC++201.6kb2024-01-10 18:26:562024-01-10 18:26:56

Judging History

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

  • [2024-01-10 18:26:56]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-01-10 18:26:56]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<bitset>
#define M 100005
using namespace std;
struct E{
	int to,nx;
}edge[M<<1];
int tot,head[M];
void Addedge(int a,int b){
	edge[++tot].to=b;
	edge[tot].nx=head[a];
	head[a]=tot;
}
bitset<1005>way[1005];
bool mark[M];
vector<int>S;
int Ans[10][2],sz;
int main(){
//	freopen("002.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)way[i].reset();
	while(m--){
		int a,b;
		scanf("%d%d",&a,&b);
		way[a].flip(b);
		way[b].flip(a);
	}
	int x=1,y=2;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)if(way[i][j]){
			Addedge(i,j);
			x=i;y=j;
		}
	}
	bool flag=false;
	for(int now=1;now<=n;now++){
		for(int i=head[now];i;i=edge[i].nx){
			for(int j=head[now];j;j=edge[j].nx){
				if(i==j)continue;
				for(int k=head[now];k;k=edge[k].nx){
					if(i==j||i==k)continue;
					if(!way[edge[j].to][edge[i].to]||!way[edge[j].to][edge[k].to])continue;
					if(!way[edge[i].to][edge[k].to])continue;
					flag=true;
					break;
				}
				if(flag)break;
			}
			if(flag)break;
		}
		if(flag)break;
	}
	if(flag)puts("ok");
	else{
		int cnt=2;
		S.push_back(x);
		S.push_back(y);
		mark[x]=mark[y]=true;
		for(int i=1;i<=n;i++){
			if(mark[i])continue;
			cnt++;
			mark[i]=true;
			S.push_back(i);
			if(cnt==4)break;
		}
		for(int i=0;i<(int)S.size();i++){
			for(int j=i+1;j<(int)S.size();j++){
				if(!way[S[i]][S[j]]){
					way[S[i]][S[j]]=way[S[j]][S[i]]=1;
					sz++;
					Ans[sz][0]=S[i];
					Ans[sz][1]=S[j];
				}
			}
		}
		puts("mark");
		for(int i=1;i<=sz;i++)printf("%d %d\n",Ans[i][0],Ans[i][1]);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer on the first run

input:

1000 3560
603 151
415 20
102 569
895 552
678 734
24 614
689 518
440 223
751 919
223 433
711 551
502 634
706 583
812 501
514 535
780 751
720 530
532 384
888 139
864 791
292 675
171 881
30 592
464 557
280 299
654 650
894 335
250 532
792 10
83 969
118 771
579 300
852 983
243 940
957 939
817 889
911 319...

output:

mark
1000 1
1000 2
974 1
974 2
1 2

input:


output:


result:

wrong answer Integer parameter [name=k] equals to 1000, violates the range [0, 5]