QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128521#4996. Icy ItinerarylikeblgWA 14ms52308kbC++141.0kb2023-07-21 08:21:312023-07-21 08:21:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-21 08:21:35]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:52308kb
  • [2023-07-21 08:21:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int const N=1e6+10;
map<int,int>G[N];
int pa1[N],pa2[N],n,m,cnt1,cnt2;
int main(){
	cin>>n>>m;
	if(m==0){
		for(int i=1;i<=n;i++)cout<<i<<" ";
		return 0;
	}
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		G[x][y]=1;
		G[y][x]=1;
	}
	pa1[1]=1;cnt1=1;
	for(int i=2;i<=n;i++){
		if(G[i][pa1[cnt1]])pa1[++cnt1]=i;
		else{
			if(!G[i][pa2[cnt2]])pa2[++cnt2]=i;
			else{
				if(G[pa1[cnt1]][pa2[cnt2]]){
					pa1[++cnt1]=pa2[cnt2];
					pa1[++cnt1]=i;
					cnt2--;
				}
				else{
					if(cnt1){
						pa2[++cnt2]=pa1[cnt1];
						pa2[++cnt2]=i;
						cnt1--;
					}
					else{
						pa1[++cnt1]=i;
					}
				}
			}
		}
	}
	int flag=1;
	for(int i=1;i<=cnt2;i++){
		if(pa2[i]==1)flag=2;
	}
	if(flag==1){
		for(int i=1;i<=cnt1;i++)cout<<pa1[i]<<" ";
		for(int i=1;i<=cnt2;i++)cout<<pa2[i]<<" ";
	}
	else{
		cout<<"1 ";
		for(int i=1;i<=cnt1;i++)cout<<pa1[i]<<" ";
		for(int i=1;i<=cnt2;i++)if(pa2[i]!=1)cout<<pa2[i]<<" ";
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 50216kb

input:

4 4
1 2
1 3
1 4
3 4

output:

1 3 2 4 

result:

ok qwq

Test #2:

score: 0
Accepted
time: 1ms
memory: 50868kb

input:

5 0

output:

1 2 3 4 5 

result:

ok qwq

Test #3:

score: -100
Wrong Answer
time: 14ms
memory: 52308kb

input:

10 10
7 8
7 5
5 2
6 1
10 7
4 6
5 8
3 2
10 5
1 10

output:

1 8 2 3 4 5 6 7 9 10 

result:

wrong answer Changed color too many times (2)