码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-01-23 23:21:59      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:训练   for   ext   class   euler   list   ace   null   system   

代码

            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)

标签:训练   for   ext   class   euler   list   ace   null   system   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!