yanguo12138 @ 2024-05-14 19:14:52
当输入数据为 3 1 2 2 3 3 1 或者 2 1 2 2 1 本地测试有的时候是对的,但是有的时候莫名其妙输出2007,为啥,好玄学啊,明明是一模一样的输入。
#include <iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
using namespace std;
#define ll long long
const int N = 2e3 + 5;
int n;
int g[N][N];
int du[N];
stack<int>a;
void dfs(int num)
{
for (int i = 1; i <= n; i++)
{
if (g[num][i] != 0)
{
g[num][i]--;
g[i][num]--;
dfs(i);
}
}
a.push(num);
return;
}
int main()
{
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
memset(g, 0, sizeof(g));
for (int i = 0; i < n; i++)
{
int num1, num2;
cin >> num1 >> num2;
du[num1]++;
du[num2]++;
g[num1][num2]++;
g[num2][num1]++;
}
int ikun = 1;
for (int i = 1; i <= sizeof(du); i++)
{
if (du[i] % 2 != 0)
{
ikun = i;
break;
}
}
dfs(ikun);
while (a.size())
{
int aa = a.top();
cout << aa << endl;
a.pop();
}
return 0;
}
by Crab_Tang @ 2024-05-14 19:55:29
@yanguo12138 但是ikun这种变量名还是不要用了,除非你在定义的时候写好是啥,不然你很容易搞不清楚。