Submission #172952

# Submission time Handle Problem Language Result Execution time Memory
172952 2020-01-02T19:24:45 Z phillip Potemkin cycle (CEOI15_indcyc) C++14
100 / 100
538 ms 115764 KB
/*#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,x,y;
int main()
{
    cin>>n>>m;

}
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int vis[1009][1009],dep[1009];
vector<int>v[1009][1009],vv[1009];
vector<pair<int,int> >p;
int cn[1009][1009];
int n,m,d;
int org;
vector<int>cc,vw[109];
void out()
{
    for(int i=0;i<cc.size();i++)cout<<cc[i]+1<<" ";
    exit(0);
}
int viss[109];
vector<int>c;
void checkmn(int x,int par)
{
    int mxd=0;
    for(int i=0;i<v[par][x].size();i++)
    {
        mxd=max(mxd,dep[v[par][x][i]]);
    }
    for(int i=mxd;i<c.size()-1;i++)
    {
        if(cn[c[i]][c[i+1]]==0)
        {
            return;
        }
    }
    for(int i=mxd;i<c.size();i++)
    {
        cout<<c[i]+1<<" ";
    }
    exit(0);
}
void dfs1(int x,int par)
{
    //cout<<x<<" "<<par<<"\n";
    cc.push_back(x);
    for(int i=0;i<vw[x].size();i++)
    {
        if(vw[x][i]==par)continue;
        if(viss[vw[x][i]])
        {
            if(vw[x][i]==org&&cc.size()>=4)continue;
            cc.pop_back();
            return;
        }
    }
    for(int i=0;i<vw[x].size();i++)
    {
        if(vw[x][i]==par)continue;
        if(vw[x][i]==org&&cc.size()>=4)out();
    }
    viss[x]=1;
    for(int i=0;i<vw[x].size();i++)
    {
        int y=vw[x][i];
        if(y==par)continue;
        dfs1(y,x);
    }
    cc.pop_back();
    viss[x]=0;
}
void dfs(int x,int par)
{
    //cout<<x<<" "<<par<<"\n";
    dep[x]=d;
    d++;
    vis[par][x]=1;
    c.push_back(x);
    for(int i=0;i<v[par][x].size();i++)
    {
        int y=v[par][x][i];
        if(vis[x][y])continue;
        if(dep[y]!=-1)
        {
            checkmn(x,par);
        }
        else dfs(y,x);
    }
    dep[x]=-1;
    d--;
    c.pop_back();
}
int main()
{
    memset(dep,-1,sizeof(dep));
    cin>>n>>m;
    if(n<=100&&m<=1000)
    {
        int x,y;
        for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        x--;y--;
        vw[x].push_back(y);
        vw[y].push_back(x);
    }
    for(int i=0;i<n;i++)
    {
        memset(vis,0,sizeof(vis));
        org=i;
        dfs1(i,i);
    }
    cout<<"no";
        return 0;
    }
    int x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        x--;y--;
        p.push_back({x,y});
        cn[x][y]=1;
        cn[y][x]=1;
        vv[x].push_back(y);
        vv[y].push_back(x);
    }
    for(int i=0;i<m;i++)
    {
        x=p[i].first;
        y=p[i].second;
        //cout<<x<<" "<<y<<": ";
        for(int j=0;j<vv[y].size();j++)
        {
            if(vv[y][j]==x)continue;
            if(cn[vv[y][j]][x])continue;
            v[x][y].push_back(vv[y][j]);
          //  cout<<v[x][y].back()<<" ";
        }
        swap(x,y);
        //cout<<"\n";
        //cout<<x<<" "<<y<<": ";
        for(int j=0;j<vv[y].size();j++)
        {
            if(vv[y][j]==x)continue;
            if(cn[vv[y][j]][x])continue;
            v[x][y].push_back(vv[y][j]);
      //      cout<<v[x][y].back()<<" ";
        }
    //    cout<<"\n";
    }
    d=1;
    for(int i=0;i<m;i++)
    {
        x=p[i].first;
        y=p[i].second;

        c.clear();
        //if(vis[x][y]==0)
        //{
            dep[x]=0;
            c.push_back(x);
            dfs(y,x);
            c.pop_back();
            dep[x]=-1;
        //}
        swap(x,y);
        c.clear();
        //if(vis[x][y]==0)
        //{
            dep[x]=0;
            c.push_back(x);
            dfs(y,x);
            c.pop_back();
            dep[x]=-1;
        //}
    }
    cout<<"no";
}

Compilation message

indcyc.cpp: In function 'void out()':
indcyc.cpp:23:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<cc.size();i++)cout<<cc[i]+1<<" ";
                 ~^~~~~~~~~~
indcyc.cpp: In function 'void checkmn(int, int)':
indcyc.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[par][x].size();i++)
                 ~^~~~~~~~~~~~~~~~~
indcyc.cpp:35:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=mxd;i<c.size()-1;i++)
                   ~^~~~~~~~~~~
indcyc.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=mxd;i<c.size();i++)
                   ~^~~~~~~~~
indcyc.cpp: In function 'void dfs1(int, int)':
indcyc.cpp:52:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vw[x].size();i++)
                 ~^~~~~~~~~~~~~
indcyc.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vw[x].size();i++)
                 ~^~~~~~~~~~~~~
indcyc.cpp:68:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vw[x].size();i++)
                 ~^~~~~~~~~~~~~
indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:84:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[par][x].size();i++)
                 ~^~~~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:137:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<vv[y].size();j++)
                     ~^~~~~~~~~~~~~
indcyc.cpp:147:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<vv[y].size();j++)
                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 28280 KB Output is correct
2 Correct 29 ms 28280 KB Output is correct
3 Correct 28 ms 28280 KB Output is correct
4 Correct 28 ms 28280 KB Output is correct
5 Correct 24 ms 24312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 28280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 28280 KB Output is correct
2 Correct 30 ms 28260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 28284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 28252 KB Output is correct
2 Correct 164 ms 28408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 27000 KB Output is correct
2 Correct 32 ms 26488 KB Output is correct
3 Correct 42 ms 27768 KB Output is correct
4 Correct 44 ms 28792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 27640 KB Output is correct
2 Correct 38 ms 28280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 46236 KB Output is correct
2 Correct 94 ms 34564 KB Output is correct
3 Correct 274 ms 47984 KB Output is correct
4 Correct 95 ms 35572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 75224 KB Output is correct
2 Correct 295 ms 81088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 482 ms 29928 KB Output is correct
2 Correct 491 ms 29548 KB Output is correct
3 Correct 500 ms 111880 KB Output is correct
4 Correct 538 ms 115764 KB Output is correct