QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#310930#4996. Icy Itineraryc20230201WA 7ms21540kbC++14814b2024-01-21 19:47:572024-01-21 19:48:03

Judging History

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

  • [2024-01-21 19:48:03]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:21540kb
  • [2024-01-21 19:47:57]
  • 提交

answer

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

const int maxn=3e5+5;

unordered_map<int,int> mp[maxn];
int nxt[maxn], pre[maxn];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n,m; cin>>n>>m;
	for(int i=1,u,v;i<=m;i++) {
		cin>>u>>v;
		mp[u][v]=mp[v][u]=1;
	}
	int pos=2, t=0;
	if(mp[1][2]) t=1;
	else t=0;
	pre[0]=2, nxt[0]=1;
	pre[1]=0, nxt[1]=2, pre[2]=1, nxt[2]=0;
	for(int i=3;i<=n;i++) {
		if(pos==1) pos=pre[0], t^=1;
		if(mp[pos][i]==t) {
			pre[nxt[pos]]=i, nxt[i]=nxt[pos], pre[i]=pos, nxt[pos]=i;
			if(nxt[i]==0||mp[i][nxt[i]]==t) pos=i;
			else pos=nxt[i];
		} else {
			nxt[pre[pos]]=i, nxt[i]=pos, pre[i]=pre[pos], pre[pos]=i;
			if(mp[pre[i]][i]==t) pos=pre[i];
		}
	}
	for(int x=nxt[0];x;x=nxt[x]) cout<<x<<' '; cout<<'\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 21540kb

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: 5ms
memory: 20576kb

input:

5 0

output:

1 2 3 4 5 

result:

ok qwq

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 20608kb

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 3 4 2 6 5 7 9 10 8 

result:

wrong answer Changed color too many times (2)