Forever_OIer @ 2023-07-16 17:24:45
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ps ' '
#define Edl '\n'
#define debug(x) cerr<<#x<<':'<<x<<'\n';
#define edl '\n'
#define cehh cerr<<'\n';
typedef long long ll;
using namespace std;
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f;}
void wrint(ll x,short e){if(x<0){putchar('-');x=-x;}if(x>9){wrint(x/10,0);}putchar(x%10+'0');if(e==1){putchar('\n');}if(e==2){putchar(' ');}}//0:啥也不加 1:换行 2:空格
const ll N=1e3 +10,INF=0x7f7f7f7f7f7f7f7f;
struct node{
int v,id;
}o;
vector<node> e[N];
ll n=0,m=0,k=0,ans=0,du[N],p1,p2,num;
bool vis[N];
bool operator <(const node &a,const node &b){
return a.v<b.v;
}
bool operator >(const node &a,const node &b){
return a.v>b.v;
}
void dfs(int u){
wrint(u,1);
for(auto i:e[u]){
if(!vis[i.id]){
vis[i.id]=1;
dfs(i.v);
break;
}
}
}
int main(){
// freopen("123.in","r",stdin);
// freopen("123.out","w",stdout);
m=read();
for(int i=1;i<=m;i++){
int u=read(),v=read();
o.id=i;
o.v=u;
e[v].push_back(o);
o.v=v;
e[u].push_back(o);
du[u]++;
du[v]++;
n=max(n,1ll*max(u,v));
}
for(int i=1;i<=n;i++){//判断奇数度点的数量
sort(e[i].begin(),e[i].end());
if(du[i]%2){
if(p1) p2=i;
else p1=i;
}
}
if(p1){
dfs(p1);
}else{
dfs(1);
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
rt,下下来数据之后发现少输出了几个点,哪位奆佬帮帮我qwq
by ZY_85 @ 2023-07-24 11:27:32
同错,#7大概400多行开始出现错误
#include<iostream>
using namespace std;
const int MAXN=501,MAXM=1024;
int n,m,d[MAXN],ans[MAXM],s[MAXN][MAXN],inx=0;
int MAX(int a,int b){
return a>b?a:b;
}
void DFS(int x){
ans[inx]=x;
for(int i=1;i<=n;i++){
if(s[x][i]>0){
s[i][x]--;
s[x][i]--;
inx++;
DFS(i);
inx--;
}
}
return;
}
int main(){
scanf("%d",&m);
for(int i=1;i<=m;i++){
int start,end;
scanf("%d%d",&start,&end);
s[start][end]++;
s[end][start]++;
d[start]++;
d[end]++;
n=MAX(MAX(start,end),n);
}
int indx=1;
for(int i=1;i<=n;i++){
if(d[i]%2){
indx=i;
break;
}
}
DFS(indx);
for(int i=0;i<=m;i++)printf("%d\n",ans[i]);
return 0;
}
by lxyt_415x @ 2023-08-09 18:50:01
同问