标签:http io ar for html sp amp on size
题意:求补图的欧拉回路
思路:模版
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxm = 40010; const int maxn = 1010; int first[maxn], cnt; struct edge { int u, v, next; }e[maxn*maxn]; int ans[maxm]; bool vis[maxm]; int len; void AddEdge(int u, int v) { e[cnt].u = u; e[cnt].v = v; e[cnt].next = first[u]; first[u] = cnt++; } void dfs(int u) { for(int i = first[u]; i != -1; i = e[i].next) { if(!vis[i]) { vis[i] = true; dfs(e[i].v); ans[len++] = i; } } } int main() { int n, s; while(scanf("%d %d", &n, &s) != EOF) { memset(first, -1, sizeof(first)); cnt = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { int x; scanf("%d", &x); if(!x && i != j) { AddEdge(i, j); } } } memset(vis, 0, sizeof(vis)); len = 0; dfs(s); for(int i = len-1; i >= 0; i--) printf("%d %d\n", e[ans[i]].u, e[ans[i]].v); } return 0; }
标签:http io ar for html sp amp on size
原文地址:http://blog.csdn.net/u011686226/article/details/38926777