제출 #362716

#제출 시각아이디문제언어결과실행 시간메모리
362716sean617슈퍼트리 잇기 (IOI20_supertrees)C++17
21 / 100
277 ms23324 KiB
#include "supertrees.h"
#include <vector>
#define N 1005

using namespace std;
int n, cnt, bu[N], num[N];
bool v[N], v2[N], co[N][N];
vector<int> gu[N], cy[N], cy2, ans, ch[N];
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 ex(int p, int q) {
    if (num[p] == 1 || num[q] == 1) return 2;
    if (v2[p] && v2[q]) return 2;
    if (v2[p] || v2[q]) return 1;
    if (num[p] == num[q]) return 1;
    return 2;
}
int construct(std::vector<std::vector<int> > p) {
    int i, j, k, t, t1, t2, t3, 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);
        if (gu[t].size() == 1) continue;
        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;
            num[i] = 1;
            cy[t].push_back(i);
        }
	}
    cnt = 1;
	for (i = 0; i < n; i++) {
        if (v[i]) continue;
        t = f(i);
        if (gu[t].size() == 1) continue;
        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;
            v2[i] = 1;
            cnt++;
            num[i] = cnt;
            cy[t].push_back(i);
            cy2.push_back(i);
        }
	}
	for (i = 0; i < n; i++) {
        int sz = cy[i].size();
        if (sz >= 2) {
            for (j = 0; j < sz; j++) {
                f_co(cy[i][j], cy[i][(j + 1) % sz]);
            }
        }
	}
	for (i = 0; i < cy2.size(); i++) {
        la = t = cy2[i];
        t2 = f(t);
        ch[i].push_back(la);
        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];
                ch[i].push_back(la);
                num[la] = num[t];
            }
        }
	}
	for (i = 0; i < n; i++) {
        for (j = 0; j < gu[i].size(); j++) {
            for (k = j + 1; k < gu[i].size(); k++) {
                t1 = gu[i][j];
                t2 = gu[i][k];
                t3 = p[t1][t2];
                if (ex(t1, t2) != t3) {
                    return 0;
                }
            }
        }
	}
//	for (i = 0; i < cy2.size(); i++) {
//        for (j = 0; j < ch[i].size(); j++) {
//            for (k = j + 1; k < ch[i].size(); k++) {
//                if (p[ch[i][j]][ch[i][k]] != 1) return 0;
//            }
//        }
//	}
	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;
}

컴파일 시 표준 에러 (stderr) 메시지

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (j = 0; j < gu[t].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~
supertrees.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if (j == gu[t].size()) {
      |             ~~^~~~~~~~~~~~~~~
supertrees.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (j = 0; j < gu[t].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~
supertrees.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         if (j == gu[t].size()) {
      |             ~~^~~~~~~~~~~~~~~
supertrees.cpp:82:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for (i = 0; i < cy2.size(); i++) {
      |              ~~^~~~~~~~~~~~
supertrees.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (j = 0; j < gu[t2].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
supertrees.cpp:96:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |         for (j = 0; j < gu[i].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~
supertrees.cpp:97:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |             for (k = j + 1; k < gu[i].size(); k++) {
      |                             ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...