lightoj 1250 - Village Postman
来源:互联网 发布:av淘宝备用网址 编辑:程序博客网 时间:2024/06/05 03:31
找欧拉回路;开始看错题了,,,笨啊。
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <stack>#include <algorithm>#include <cmath>#include <map>#define LL long long#define DB doubleusing namespace std;const int N = 209;const int M = 1009;const int INF = 0x3f3f3f3f;int n,m;int re[N];int ans;int path[M],cnt;int in[N];struct LT{ int to,nex;} L[M<<1];int F[N],C=2;int v[M];void add(int f,int t){ L[C].nex = F[f];L[C].to = t; F[f] = C++;}void dfs(int k){ for(int i=F[k];i;i=L[i].nex){ if(v[i>>1]) continue; int to = L[i].to; v[i>>1] = 1; dfs(to); } path[cnt++] = k;}void solve(int T){ ans =0; for(int i=1;i<=n;i++) ans += re[i]; ans = ans-(n+1)*n/2-m; cnt = 0; in[1]--; dfs(1); printf("Case %d: %d\n",T,ans); for(int i=0;i<cnt;i++) { if(i) printf(" ");printf("%d",path[i]); }puts("");}int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int cas,T=1;scanf("%d",&cas); while(cas--) { scanf("%d%d",&n,&m); ans =0;cnt = 0;C=2; memset(in,0,sizeof(in)); memset(F,0,sizeof(F)); memset(v,0,sizeof(v)); for(int i=1;i<=n;i++) { scanf("%d",&re[i]); } int a,b; for(int i=0;i<m;i++) { scanf("%d%d",&a,&b); add(a,b);add(b,a); in[a]++;in[b]++; } solve(T);T++; } return 0;}
- lightoj 1250 - Village Postman
- Cottage Village
- Postman
- PostMan
- Postman
- postman
- postman
- Postman
- PostMan
- postman
- postman
- PostMan
- postman
- PostMan
- postman
- PostMan
- A. Cottage Village
- 大学生村官 little village official
- JAVA集合
- Thinking in Java之ArrayList、Vector比较分析
- Shell脚本学习(二):条件语句与循环语句
- 在Web开发中使用多点触碰技术
- 利用run-as命令在不root情况下读取data下面的sqlite数据
- lightoj 1250 - Village Postman
- C/C++面试题汇总
- VS2008与Matlab混合编程设置
- Android之activity详述
- xml相关知识总结
- Android Unity3D基础
- gentoo内核编译
- 一、ORACLE体系结构
- !!!Obj-C 2.0 -- Chapter 2 Defining a Class