zoukankan      html  css  js  c++  java
  • noip 2018 Day2 T1 旅行

    暴力删边,暴力枚举

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define MAXM 5010
    
    inline int read()
    {
        int x = 0,ff = 1;char ch = getchar();
        while(!isdigit(ch))
        {
            if(ch == '-') ff = -1;
            ch = getchar();
        }
        while(isdigit(ch))
        {
            x = (x << 1) + (x << 3) + (ch ^ 48);
            ch = getchar();
        }
        return x * ff;
    }
    
    inline void write(int x)
    {
        if(x < 0) putchar('-'),x = -x;
        if(x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
    
    int a,b,x,y,dx,dy,top = 0,c[MAXM],vis[MAXM],T[MAXM],m[MAXM],e[MAXM][5]; 
    vector < int > q[MAXM];
    
    inline void dfs(int x)
    {
    
        T[++top] = x; vis[x] = true;
        int l = q[x].size();
        for(int i = 0;i < l;++i)
        {        
            int y = q[x][i];
            if((vis[y]) || (x == dx && y == dy) || (x == dy && y == dx)) continue;
            dfs(y);
        }
        return ;
    }
    
    inline void check()
    {
        for(int i = 1;i <= a;++i)
        {
            if(m[i] != T[i])
            {
                if(m[i] < T[i]) return ;
                break;
            }
        }
        for(int i = 1;i <= a;++i)
        m[i] = T[i];
    }
    
    int main()
    { 
        memset(m,0x3f,sizeof(m));
        a = read(); b = read();
        for(int i = 1;i <= b;++i)
        {
            int x,y;
            x = read(); y = read();
            q[x].push_back(y);
            q[y].push_back(x);
            e[i][0] = x;
            e[i][1] = y;
        }
        for(int i = 1;i <= a;++i)
            sort(q[i].begin(),q[i].end());
        if(b == a - 1)    
        {
            dx = -1; dy = -1;
            dfs(1);
            for(int i = 1;i <= a;++i)
            write(T[i]),putchar(' ');
        }
        else
        {
            for(int i = 1;i <= b;++i)
            {
                top = 0;
                dx = e[i][0];
                dy = e[i][1];
                memset(T,0,sizeof(T));
                memset(vis,false,sizeof(vis));
                dfs(1);
                if(top != a) continue;
                check(); 
            } 
            for(int i = 1;i <= a;++i)
            write(m[i]),putchar(' ');
        }
        return 0;
    }
  • 相关阅读:
    SpringCloud-sleuth-zipkin链路追踪
    关于encodeURI() 踩的坑
    兄弟ifream的方法调用
    jq为什么能用$操作
    js获取一周的日期范围
    layui中实现上传图片压缩
    input预览上传图片
    js获取地址栏参数
    计算两天之间的天数差
    文字始终均匀分布整个div
  • 原文地址:https://www.cnblogs.com/AK-ls/p/10385363.html
Copyright © 2011-2022 走看看