답안 #594357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
594357 2022-07-12T11:14:57 Z andrei_boaca Potemkin cycle (CEOI15_indcyc) C++14
80 / 100
989 ms 1876 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")

using namespace std;
mt19937 rng(time(NULL));
vector<int> muchii[1005];
bool adj[1005][1005];
auto S=chrono::steady_clock::now();
int n,m;
vector<int> v;
int use[1005];
int start=0;
void dfs(int nod)
{
    auto E=chrono::steady_clock::now();
    int x=chrono::duration_cast<chrono::milliseconds>(E - S).count();
    if(v.size()>=21)
        return;
    if(x>=990)
    {
        cout<<"no";
        exit(0);
    }
    use[nod]=v.size();
    bool good=1;
    int pmax=0;
    int pmin=1e9;
    vector<int> mypoz;
    for(int i:muchii[nod])
    {
        if(use[i])
        {
            if(i==v[v.size()-2])
                continue;
            if(i==start)
            {
                if(v.size()>=4);
                else
                    good=0;
            }
            else if(i!=v[v.size()-2])
                good=0;
            pmax=max(pmax,use[i]);
            pmin=min(pmin,use[i]);
            mypoz.push_back(use[i]);
        }
    }
    sort(mypoz.begin(),mypoz.end());
    if(v.size()-pmax+1>=4&&pmax!=0)
    {
        for(int i=pmax-1;i<v.size();i++)
            cout<<v[i]<<' ';
        exit(0);
    }
    if(adj[nod][start]&&pmin+1>=4&&pmin!=1e9)
    {
        for(int i=0;i<pmin;i++)
            cout<<v[i]<<' ';
        cout<<nod;
        exit(0);
    }
    for(int i=1;i<mypoz.size();i++)
    {
        int st=mypoz[i-1];
        int dr=mypoz[i];
        if(dr-st+2>=4)
        {
            for(int j=st-1;j<dr;j++)
                cout<<v[j]<<' ';
            cout<<nod;
            exit(0);
        }
    }
    if(good)
    {
        for(int i:muchii[nod])
            if(!use[i])
            {
                v.push_back(i);
                dfs(i);
                use[i]=0;
                v.pop_back();
            }
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int a,b;
        cin>>a>>b;
        muchii[a].push_back(b);
        muchii[b].push_back(a);
        adj[a][b]=adj[b][a]=1;
    }
    for(int i=1;i<=n;i++)
        shuffle(muchii[i].begin(),muchii[i].end(),rng);
    vector<int> nodes;
    for(int i=1;i<=n;i++)
        nodes.push_back(i);
    shuffle(nodes.begin(),nodes.end(),rng);
    int limit=(4000*n)/10000+1;
    for(int i:nodes)
        if(i<=limit)
    {
        start=i;
        v.clear();
        v.push_back(i);
        for(int j=1;j<=n;j++)
            use[j]=0;
        dfs(i);
    }
    cout<<"no";
    return 0;
}

Compilation message

indcyc.cpp: In function 'void dfs(int)':
indcyc.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int i=pmax-1;i<v.size();i++)
      |                          ~^~~~~~~~~
indcyc.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i=1;i<mypoz.size();i++)
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 226 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 972 ms 668 KB Output is correct
2 Correct 96 ms 684 KB Output is correct
3 Correct 18 ms 716 KB Output is correct
4 Correct 984 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 596 KB Output is correct
2 Correct 989 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1876 KB Output is correct
2 Incorrect 971 ms 1776 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1580 KB Output is correct
2 Correct 971 ms 1592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 982 ms 1768 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -