中国设计网站排行榜前十名,网站风险解除,百度账号登录不了,免费的行情软件网站下载http://poj.org/problem?id1041 (题目链接) 题意 给出一张无向图#xff0c;求字典序最小欧拉回路。 Solution 这鬼畜的输入是什么心态啊mdzz#xff0c;这里用vector储存边#xff0c;便于边的排序。瞬间变成STL常数boy →_→。 细节 数组大小把握好。 代码 // poj1041
#i…http://poj.org/problem?id1041 (题目链接) 题意 给出一张无向图求字典序最小欧拉回路。 Solution 这鬼畜的输入是什么心态啊mdzz这里用vector储存边便于边的排序。瞬间变成STL常数boy →_→。 细节 数组大小把握好。 代码 // poj1041
#includealgorithm
#includeiostream
#includecstdlib
#includecstring
#includecstdio
#includevector
#includecmath
#define LL long long
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a.in,r,stdin),freopen(a.out,w,stdout);
using namespace std;const int maxn2000;
struct edge {int to,id;friend bool operator (const edge a,const edge b) {return a.idb.id;}
};
int vis[maxn],r[maxn],s[maxn],top,rt;
vectoredge e[maxn];void dfs(int x) {for (int i0;ie[x].size();i) if (!vis[e[x][i].id]) {vis[e[x][i].id]1;dfs(e[x][i].to);s[top]e[x][i].id;}
}
int main() {int x,y,z;while (scanf(%d%d,x,y)!EOF x y) {memset(vis,0,sizeof(vis));for (int i1;imaxn;i) e[i].clear(),r[i]0;rtmin(x,y);while (x y) {scanf(%d,z);e[x].push_back((edge){y,z});e[y].push_back((edge){x,z});r[x];r[y];scanf(%d%d,x,y);}int flag0;for (int i1;imaxn;i) if (r[i]1) {flag1;break;}if (flag) {puts(Round trip does not exist.);continue;}for (int i1;imaxn;i) sort(e[i].begin(),e[i].end());top0;dfs(rt);while (top) printf(%d ,s[top--]);puts();}return 0;
}转载于:https://www.cnblogs.com/MashiroSky/p/5991367.html