首页 > 其他 > 详细

「日常训练」The Necklace(UVA-10054)

时间:2019-01-23 23:05:40      阅读:196      评论:0      收藏:0      [点我收藏+]

代码

            for(int i=0; i!=n; ++i)
            {
                int u = cin.nextInt();
                int v = cin.nextInt();
                edges.add(new Edge(u,v));
                startpnt = u;
                if(g.get(u)==null) g.put(u, new ArrayList<Integer> ());
                g.get(u).add(edges.size()-1);
                edges.add(new Edge(v,u));
                if(g.get(v)==null) g.put(v, new ArrayList<Integer> ());
                g.get(v).add(edges.size()-1);
            }
            boolean ok = true;
            for(int i=1;i<=n;++i)
            {
                if(g.get(i)==null) continue;
                if(g.get(i).size()%2==1)
                {
                    ok=false;
                    break;
                }
            }
            if(ok) euler(startpnt);
            System.out.println("Case #"+kase);
            if(ok && stack.size()==n)
            {
                while(!stack.isEmpty())
                {
                    System.out.println(stack.peek().u+" "+stack.peek().v);
                    stack.pop();
                }
            }
            else
            {
                System.out.println("some beads may be lost");
            }
            System.out.println();
        }
    }
}

「日常训练」The Necklace(UVA-10054)

原文:https://www.cnblogs.com/samhx/p/UVa-10054.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!