zoukankan      html  css  js  c++  java
  • Watchcow

    传送门

    题目大意:

    给你一幅连通的图,要求从起点1开始走,要经过每条边刚好两次,并且最终回到1起点。

    思路:将无向图转换成有向图求欧拉回路。

    #include<cstdio>
    #define N 11000
    #define M 110000//由于是将无向图转换成有向图,所以边变为原来的两倍。
                   //因此*2,这个地方调了好几天,满满的都是泪啊。 
    int n,m; 
    struct map
    {
        int tot;
        int head[N],v[M],pre[M];
        /*
          pre[]里存的是a点连得另一个点的编号。 
          v[]存的是当前边连得b点。 
        */ 
        bool f[M];
        void addedge(int a,int b)
        {
            tot++;
            v[tot]=b;
            pre[tot]=head[a];
            head[a]=tot;
        }
    }G;
    void dfs(int now)
    {
        for (int p=G.head[now];p;p=G.pre[p])
          {
               if (!G.f[p])
                 {
                  G.f[p]=1;
                  dfs(G.v[p]);                 
               }
          } 
          printf("%d
    ",now);
    }
    int main()
    {
        scanf("%d%d",&n,&m);
        for (int i=1;i<=m;i++)
          {
              int a,b;
              scanf("%d%d",&a,&b);
              G.addedge(a,b);
              G.addedge(b,a);
          }
        dfs(1);
        return 0;
    }
    I'm so lost but not afraid ,I've been broken and raise again
  • 相关阅读:
    BZOJ 5314: [Jsoi2018]潜入行动
    BZOJ 3420: Poi2013 Triumphal arch
    BZOJ 1135: [POI2009]Lyz
    BZOJ 4247: 挂饰
    本地
    生成config文件到内存中
    微信获取access_token和curl
    php生成静态页面
    curl
    分页
  • 原文地址:https://www.cnblogs.com/sjymj/p/5514151.html
Copyright © 2011-2022 走看看