답안 #69070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69070 2018-08-19T19:12:09 Z Bodo171 Potemkin cycle (CEOI15_indcyc) C++14
0 / 100
465 ms 3468 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int nmax=1005;
bool ad[nmax][nmax];
vector<int> v[nmax],cyc;
int lev[nmax],prec[nmax];
int i,n,m,u,p,x,nod,a,b,start;
void construieste(int A,int B)
{
    while(A!=B)
    {
        cyc.push_back(A);
        A=prec[A];
    }
    cyc.push_back(B);
    for(int i=0;i<cyc.size();i++)
        cout<<cyc[i]<<' '<<ad[start][cyc[i]]<<'\n';
    cyc.push_back(start);
}
void dfs(int x,int lst,bool valid)
{
    if(start==2)
        cout<<x<<' '<<lst<<' '<<valid<<'\n';
    for(int i=0;i<v[x].size();i++)
        if(prec[v[x][i]]&&v[x][i]!=prec[x]&&v[x][i]!=start)
    {
        if(lev[v[x][i]]>=lev[lst])
            valid=0;
    }
    if(ad[start][x]&&(!cyc.size()))
    {
        if(valid&&lev[x]-lev[lst]>1)
        {
            construieste(x,lst);
        }
        else
            lst=x,valid=1;
    }
    for(int i=0;i<v[x].size();i++)
        if(!prec[v[x][i]])
    {
        prec[v[x][i]]=x;lev[v[x][i]]=lev[x]+1;
        dfs(v[x][i],lst,valid);
    }
}
void solve()
{
    for(i=1;i<=n;i++)
        prec[i]=lev[i]=0;
    u=0;prec[start]=-1;
    for(int i=0;i<v[start].size();i++)
        if(!prec[v[start][i]])
      {
        prec[v[start][i]]=-1;
        dfs(v[start][i],0,0);
      }
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>a>>b;
        ad[a][b]=ad[b][a]=1;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(i=1;i<=n;i++)
        ad[i][i]=1;
    for(start=1;start<=n&&cyc.size()==0;start++)
    {
        solve();
    }
    if(!cyc.size())
    {
        cout<<"no";
    }
    else
    {
        cout<<cyc.size()<<'\n';
        for(i=0;i<cyc.size();i++)
            cout<<cyc[i]<<' ';
    }
    return 0;
}

Compilation message

indcyc.cpp: In function 'void construieste(int, int)':
indcyc.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<cyc.size();i++)
                 ~^~~~~~~~~~~
indcyc.cpp: In function 'void dfs(int, int, bool)':
indcyc.cpp:27:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
indcyc.cpp:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
indcyc.cpp: In function 'void solve()':
indcyc.cpp:54:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[start].size();i++)
                 ~^~~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:86:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<cyc.size();i++)
                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Integer 0 violates the range [1, 4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 488 KB Integer 0 violates the range [1, 10]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 488 KB Integer 0 violates the range [1, 10]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 668 KB Integer 0 violates the range [1, 100]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 796 KB Integer 0 violates the range [1, 100]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 1020 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 1060 KB Integer 0 violates the range [1, 300]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 465 ms 2764 KB Integer 0 violates the range [1, 1000]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 218 ms 2764 KB Integer 0 violates the range [1, 1000]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 322 ms 3468 KB Integer 0 violates the range [1, 440]
2 Halted 0 ms 0 KB -