답안 #69071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69071 2018-08-19T19:13:42 Z Bodo171 Potemkin cycle (CEOI15_indcyc) C++14
40 / 100
596 ms 3920 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);
    cyc.push_back(start);
}
void dfs(int x,int lst,bool valid)
{
    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
    {
        for(i=0;i<cyc.size();i++)
            cout<<cyc[i]<<' ';
    }
    return 0;
}

Compilation message

indcyc.cpp: In function 'void dfs(int, int, bool)':
indcyc.cpp:23:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
indcyc.cpp:38: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:50: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:81:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<cyc.size();i++)
                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 2 ms 544 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 752 KB Output is correct
2 Correct 3 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 804 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1188 KB Output is correct
2 Incorrect 20 ms 1188 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 1188 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 585 ms 2272 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 239 ms 2272 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 329 ms 2272 KB Output is correct
2 Correct 342 ms 3060 KB Output is correct
3 Incorrect 596 ms 3920 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -