QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#130878#4996. Icy ItinerarycztqRE 1ms5860kbC++14982b2023-07-25 16:06:542023-07-25 16:06:58

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-25 16:06:58]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5860kb
  • [2023-07-25 16:06:54]
  • 提交

answer

#include<bits/stdc++.h>
#define N 300010
using namespace std;
struct edge{
	int v,ne;
}e[N<<1];
int n,m,cnt,h[N];
deque<int>q1,q2;
void add(int u,int v){
	e[++cnt].v = v;
	e[cnt].ne = h[u];
	h[u] = cnt;
}
bool check(int u,int v){
	for(int i = h[u];i;i = e[i].ne)
		if(e[i].v==v) return true;
	return false;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	q1.push_back(1);
	q2.push_back(2);
	for(int i = 3;i<=n;i++){
		if(check(i,q1.back())){
			q1.push_back(i);
		}else if(check(q2.back(),i)){
			if(check(q1.back(),q2.back())){
				q1.push_back(q2.back());
				q2.pop_back();
				q1.push_back(i);
			}else{
				q2.push_back(q1.back());
				q1.pop_back();
				q2.push_back(i);
			}
		}else q2.push_back(i);
	}
	while(q1.size()){
		printf("%d ",q1.front());
		q1.pop_front();
	}
	while(q2.size()){
		printf("%d ",q2.front());
		q2.pop_front();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5812kb

input:

4 4
1 2
1 3
1 4
3 4

output:

1 3 4 2 

result:

ok qwq

Test #2:

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

input:

5 0

output:

1 2 3 4 5 

result:

ok qwq

Test #3:

score: -100
Runtime Error

input:

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

output:


result: