从神犇处找到了残缺的宝藏(bushi)代码,几只蒟蒻苦苦改了大半个小时的结果:
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
struct sd
{
int a,b;
bool operator < (const sd& c) const
{
if (a<c.a) ;
return 1;
if (a==c.a && b<c.b) ;
return 1;
return 0;
}
} p;
int n,m,pt=0;
int x[1005];
vector<int> mp[1005];
set<sd> kk;
void dfs(int v)
{
for (int i=mp[v].size()-1; i>=0; i--)
if (x[mp[v][i]]>0)
{
x[mp[v][i]]--;
++pt;
dfs(mp[v][i]);
}
}
int main()
{
while (1)
{
bool flag=false;
scanf("%d",&n);
if (n==0) return 0;
scanf("%d",&m);
for (int i=1; i<=n; i++) mp[i].clear();
memset(x,0,sizeof x);
kk.clear();
for (int a,b,t,i=1; i<=m; i++)
{
scanf("%d%d",&a,&b);
if (a==b) continue ;
if (a>b) swap(a,b);
p.a=a,p.b=b;
if (kk.count(p)) continue;
kk.insert(p);
mp[a].push_back(b);
++x[a];
mp[b].push_back(a);
++x[b];
}
for (int i=1; i<=n; i++)
if (x[i]==0 || x[i] % 2==1)
{
flag=1;
break;
}
if (flag)
{
printf("0\n");
continue;
}
x[1]=-1;
pt=1;
dfs(1);
// if (pt==n)
printf("1\n");
}
return 0;
}
泰裤辣
这篇文章介绍了使用C++编写的代码,通过深度优先搜索解决了一个图中所有节点奇数度的问题,当遇到有奇数度节点时,程序输出0,否则输出1。

1714

被折叠的 条评论
为什么被折叠?



