답안 #362699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362699 2021-02-04T07:00:36 Z sean617 슈퍼트리 잇기 (IOI20_supertrees) C++17
0 / 100
1 ms 364 KB
#include "supertrees.h"
#include <vector>
#define N 1005

using namespace std;
int n, bu[N];
bool v[N], co[N][N];
vector<int> gu[N], cy, cy2, ans;
vector<std::vector<int> > answer;
int f(int p) {
    if (bu[p] == p) return p;
    else return bu[p] = f(bu[p]);
}

void f_co(int p, int q) {
    co[p][q] = co[q][p] = 1;
}
int construct(std::vector<std::vector<int> > p) {
    int i, j, t, t1, t2, la;
	n = p.size();
	for (i = 0; i < n; i++) bu[i] = i;
	for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            if (p[i][j]== 0) continue;
            if (p[i][j] == 3) return 0;
            t1 = f(i);
            t2 = f(j);
            if (t1 != t2) bu[t1] = t2;
        }
	}
	for (i =0; i < n; i++) {
        t = f(i);
        gu[t].push_back(i);
	}
	for (i = 0; i < n; i++) {
        t = f(i);
        for (j = 0; j < gu[t].size(); j++) {
            if (gu[t][j] == i) continue;
            if (p[i][gu[t][j]] != 2) break;
        }
        if (j == gu[t].size()) {
            v[i] = 1;
            cy.push_back(i);
        }
	}
	for (i = 0; i < n; i++) {
        if (v[i]) continue;
        t = f(i);
        for (j = 0; j < gu[t].size(); j++) {
            if (gu[t][j] == i) continue;
            if (p[i][gu[t][j]] == 1 && v[gu[t][j]]) break;
        }
        if (j == gu[t].size()) {
            v[i] = 1;
            cy.push_back(i);
            cy2.push_back(i);
        }
	}
	int sz = cy.size();
	for (i = 0; i < sz; i++) {
        f_co(cy[i], cy[(i + 1) % sz]);
	}
	for (i = 0; i < cy2.size(); i++) {
        la = t = cy2[i];
        t2 = f(t);
        for (j = 0; j < gu[t2].size(); j++) {
            if (gu[t2][j] != t && p[t][gu[t2][j]] == 1) {
                f_co(la, gu[t2][j]);
                la = gu[t2][j];
            }
        }
	}
	for (i = 0; i < n; i++) {
        ans.clear();
        for (j =0; j < n; j++) {
            ans.push_back(co[i][j]);
        }
		answer.push_back(ans);
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for (j = 0; j < gu[t].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~
supertrees.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if (j == gu[t].size()) {
      |             ~~^~~~~~~~~~~~~~~
supertrees.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (j = 0; j < gu[t].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~
supertrees.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         if (j == gu[t].size()) {
      |             ~~^~~~~~~~~~~~~~~
supertrees.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for (i = 0; i < cy2.size(); i++) {
      |              ~~^~~~~~~~~~~~
supertrees.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (j = 0; j < gu[t2].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB b[0][0] is not 0
2 Halted 0 ms 0 KB -