답안 #311638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311638 2020-10-10T20:39:48 Z ly20 Potemkin cycle (CEOI15_indcyc) C++17
40 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1123;
vector <int> grafo[MAXN];
vector <int> resp;
int marc[MAXN];
void dfs(int v, int p, int a) {
    marc[v] = 1;
    for(int i = 0; i < grafo[v].size(); i++) {
        int viz = grafo[v][i];
        if(viz == p || marc[viz] == 1) continue;
        if((1 << viz) & a) {
            dfs(viz, v, a);
        }
    }
}
void dfs2(int v, int p, int a) {
    resp.push_back(v);
    marc[v] = 1;
    for(int i = 0; i < grafo[v].size(); i++) {
        int viz = grafo[v][i];
        if(viz == p || marc[viz] == 1) continue;
        if((1 << viz) & a) {
            dfs2(viz, v, a);
        }
    }
}
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    if(n > 10) return 0;
    for(int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b); a--; b--;
        grafo[a].push_back(b); grafo[b].push_back(a);
    }
    for(int i = 0; i < (1 << n); i++) {
        if( __builtin_popcount(i) < 4) continue;
        bool ok = true;
        int ft;
        for(int j = 0; j < n; j++) {
            if(i & (1 << j)) {
                ft = j;
                int cnt = 0;
                for(int k = 0; k < grafo[j].size(); k++) {
                    int viz = grafo[j][k];
                    if((1 << viz) & i) {
                        cnt++;
                    }
                }
                if(cnt != 2) {
                    ok = false;
                }
            }
        }
        for(int j = 0; j < n; j++) marc[j] = 0;
        dfs(ft, ft, i);
        for(int j = 0; j < n; j++) {
            if(marc[j] == 0 && (i & (1 << j))) ok = false;
        }
        if(ok) {
            for(int j = 0; j < n; j++) marc[j] = 0;
            dfs2(ft, ft, i);
            break;
        }
    }
    if(resp.size() == 0) {
        printf("no\n");
    }
    else {
        for(int i = 0; i < resp.size(); i++) printf("%d ", resp[i] + 1);
        printf("\n");
    }
    return 0;
}

Compilation message

indcyc.cpp: In function 'void dfs(int, int, int)':
indcyc.cpp:9:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
indcyc.cpp: In function 'void dfs2(int, int, int)':
indcyc.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:45:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |                 for(int k = 0; k < grafo[j].size(); k++) {
      |                                ~~^~~~~~~~~~~~~~~~~
indcyc.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int i = 0; i < resp.size(); i++) printf("%d ", resp[i] + 1);
      |                        ~~^~~~~~~~~~~~~
indcyc.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         scanf("%d %d", &a, &b); a--; b--;
      |         ~~~~~^~~~~~~~~~~~~~~~~
indcyc.cpp:63:17: warning: 'ft' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |             dfs2(ft, ft, i);
      |             ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Too short sequence
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Too short sequence
2 Incorrect 1 ms 384 KB Unexpected end of file - token expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Too short sequence
2 Incorrect 0 ms 384 KB Unexpected end of file - token expected
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Too short sequence
2 Correct 1 ms 384 KB Too short sequence
3 Incorrect 1 ms 384 KB Unexpected end of file - token expected
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Too short sequence
2 Incorrect 0 ms 384 KB Unexpected end of file - token expected
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Too short sequence
2 Incorrect 0 ms 384 KB Unexpected end of file - token expected
3 Halted 0 ms 0 KB -