QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#62774#4996. Icy ItineraryretaliatorEliteWA 1ms3360kbC++14971b2022-11-20 12:01:032022-11-20 12:03:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-20 12:03:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3360kb
  • [2022-11-20 12:01:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int n,m;

set<pair<int,int> > e;
stack<int> is,ch;
int mid;

int ans[300010];

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		int u,v;
		cin>>u>>v;
		if(u>v) swap(u,v);
		e.insert(make_pair(u,v));
	}
	mid=1;
	for(int i=2;i<=n;++i){
		if(e.find(make_pair(mid,i))!=e.end()){
			ch.push(mid);
			mid=i;
			if(is.empty()==false&&e.find(make_pair(is.top(),i))!=e.end()){
				ch.push(mid);
				mid=is.top();
				is.pop();
			}
		}
		else{
			is.push(mid);
			mid=i;
			if(ch.empty()==false&&e.find(make_pair(ch.top(),i))==e.end()){
				is.push(mid);
				mid=ch.top();
				ch.pop();
			}
		}
	}
	int tmp=is.size();
	for(int i=1;i<=tmp;++i){
		ans[tmp-i+1]=is.top();
		is.pop();
	}
	ans[tmp+1]=mid;
	tmp=tmp+2;
	while(ch.empty()==false){
		ans[tmp]=ch.top();
		tmp++;
		ch.pop();
	}
	for(int i=1;i<=n;++i){
		cout<<ans[i]<<' ';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3360kb

input:

4 4
1 2
1 3
1 4
3 4

output:

2 4 3 1 

result:

wrong answer The first number wasn't 1