• 【Codeforces Beta Round #88 C】Cycle


    Link:http://codeforces.com/problemset/problem/117/C

    Description

    问你一张图里面有没有一个三元环,有的话就输出。

    Solution

    O(N2)写个图的遍历就行;
    主程序里的for循环,是防止多个连通块.

    NumberOf WA

    0

    Reviw


    Code

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    #define ri(x) scanf("%d",&x)
    #define rl(x) scanf("%lld",&x)
    #define rs(x) scanf("%s",x+1)
    #define oi(x) printf("%d",x)
    #define ol(x) printf("%lld",x)
    #define oc putchar(' ')
    #define os(x) printf(x)
    #define all(x) x.begin(),x.end()
    #define Open() freopen("F:\rush.txt","r",stdin)
    #define Close() ios::sync_with_stdio(0)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 5000;
    
    int n,v[N+10];
    char s[N+10][N+10];
    
    bool dfs(int x,int fa){
        v[x] = 1;
        rep1(i,1,n)
            if (s[x][i]-'0'){
                if (i!=fa && (s[i][fa]-'0')){
                    oi(x),oc,oi(i),oc,oi(fa),puts("");
                    return true;
                }
                if (!v[i])
                    if (dfs(i,x)) return true;
            }
        return false;
    }
    
    int main(){
        //Open();
        //Close();
        ri(n);
        rep1(i,1,n) rs(s[i]);
    
        rep1(i,1,n)
            if (!v[i])
                if (dfs(i,i)) return 0;
        puts("-1");
        return 0;
    }
  • 相关阅读:
    求超大文件上传方案( vue )
    求超大文件上传方案( csharp )
    求超大文件上传方案( c# )
    求超大文件上传方案( .net )
    求超大文件上传方案( asp.net )
    求超大文件上传方案( php )
    求超大文件上传方案( jsp )
    用浏览器 实现断点续传 (HTTP)
    shuffle() 函数
    no.random.randn
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626108.html
Copyright © 2020-2023  润新知