답안 #47933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47933 2018-05-09T08:17:07 Z Extazy Potemkin cycle (CEOI15_indcyc) C++17
40 / 100
802 ms 2300 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int N = 1007;

int n,m;
vector < int > v[N];
int st[N],pos[N],sz;
bool used[N];
vector < int > ans;
bool have[N][N];

bool cmp_pos(int a, int b) {
  return pos[a]>pos[b];
}

void print() {
  for(int i=0;i<(int)(ans.size());i++) {
    if(i>0) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
}

bool dfs(int node, int from=-1) {
  used[node]=true;
  st[++sz]=node;
  pos[node]=sz;

  int i,len,last=-1;
  vector < int > in;

  for(i=0;i<(int)(v[node].size());i++) if(v[node][i]!=from && pos[v[node][i]]!=-1) {
    in.push_back(v[node][i]);
  }

  sort(in.begin(),in.end(),cmp_pos);

  for(i=0;i<(int)(in.size());i++) {
    if(last==-1) len=pos[node]-pos[in[i]]+1;
    else len=last-pos[in[i]]+2;

    if(len>3) {
      if(last==-1) {
        for(i=pos[in[i]];i<=pos[node];i++) ans.push_back(st[i]);
      }
      else {
        for(i=pos[in[i]];i<=last;i++) ans.push_back(st[i]);
        ans.push_back(node);
      }
      //print();
      return true;
    }
    last=pos[in[i]];
  }

  for(i=0;i<(int)(v[node].size());i++) if(!used[v[node][i]]) if(dfs(v[node][i],node)) {
    return true;
  }

  --sz;
  pos[node]=-1;

  return false;
}

bool check() {
  int i,j;

  for(i=0;i<(int)(ans.size());i++) {
    for(j=i+2;j<(int)(ans.size())-(i==0);j++) {
      if(have[ans[i]][ans[j]]) return false;
    }
  }

  return true;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int it,i,x,y;

  scanf("%d %d", &n, &m);
  for(i=1;i<=m;i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
    have[x][y]=have[y][x]=true;
  }


  while(clock()<=0.80*CLOCKS_PER_SEC) {
    for(i=1;i<=n;i++) {
      random_shuffle(v[i].begin(),v[i].end());
    }
    
    memset(used,0,sizeof(used));
    memset(pos,-1,sizeof(pos));
    ans.clear();
    sz=0;

    for(i=1;i<=n;i++) if(!used[i]) {
      if(dfs(i)) {
        if(check()) {
          print();
          return 0;
        }
        else {
          break;
        }
      }
    }
  }

  printf("no\n");

  return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:84:7: warning: unused variable 'it' [-Wunused-variable]
   int it,i,x,y;
       ^~
indcyc.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &x, &y);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 800 ms 580 KB Output is correct
3 Correct 800 ms 580 KB Output is correct
4 Correct 800 ms 608 KB Output is correct
5 Correct 800 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 660 KB Output is correct
2 Correct 800 ms 660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 800 ms 760 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 800 ms 980 KB Output is correct
2 Incorrect 800 ms 1020 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 800 ms 1132 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 802 ms 2284 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 800 ms 2284 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 801 ms 2300 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -