답안 #953265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953265 2024-03-25T18:38:01 Z Desh03 슈퍼트리 잇기 (IOI20_supertrees) C++17
46 / 100
183 ms 24152 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

int construct(vector<vector<int>> p) {
    int n = p.size();
    vector<bool> vis(n);
    vector<vector<int>> b(n, vector<int> (n));
    for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        queue<int> q;
        q.push(i);
        vector<int> nodes;
        bool two = 0, three = 0;
        vector<bool> vis_(n);
        while (q.size()) {
            int u = q.front();
            q.pop();
            if (vis[u]) continue;
            vis[u] = vis_[u] = 1;
            nodes.push_back(u);
            for (int j = 0; j < n; j++) {
                if (p[i][j] == 2) two = 1;
                if (p[i][j] == 3) three = 1;
                if (vis[j] && !vis_[j] && p[i][j]) return 0;
                if (!vis[j] && p[i][j]) {    
                    q.push(j);
                }
            }
        }
        for (int j = 0; j < nodes.size(); j++) {
            for (int k = j + 1; k < nodes.size(); k++) {
                if (!p[nodes[j]][nodes[k]]) {
                    return 0;
                }
            }
        }
        if (two && three) return 0;
        vector<vector<int>> trees;
        vector<bool> vis2(n);
        for (int u : nodes) {
            if (vis2[u]) continue;
            trees.push_back({});
            queue<int> q2;
            q2.push(u);
            while (q2.size()) {
                int v = q2.front();
                q2.pop();
                if (vis2[v]) continue;
                vis2[v] = 1;
                trees.back().push_back(v);
                for (int j = 0; j < n; j++) {
                    if (!vis2[j] && p[v][j] == 1) {
                        q2.push(j);
                    }
                }
            }
        }
        int sz = trees.size();
        if (two && sz < 3) return 0;
        if (three && sz < 4) return 0;
        for (int j = 0; j < sz; j++) {
            for (int k = 0; k < trees[j].size(); k++) {
                for (int l = k + 1; l < trees[j].size(); l++) {
                    if (p[trees[j][k]][trees[j][l]] > 1) {
                        return 0;
                    }
                }
            }
        }
        for (int j = 0; j < sz; j++) {
            int u = trees[j].back(), v = trees[(j + 1) % sz].back();
            if (u != v) {
                b[u][v] = b[v][u] = 1;
            }
            for (int k = 0; k < trees[j].size() - 1; k++) {
                u = trees[j][k], v = trees[j][k + 1];
                b[u][v] = b[v][u] = 1;
            }
        }
        if (three) {
            b[trees[0].back()][trees[2].back()] = b[trees[2].back()][trees[0].back()] = 1;
        }
    }
    build(b);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int j = 0; j < nodes.size(); j++) {
      |                         ~~^~~~~~~~~~~~~~
supertrees.cpp:33:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int k = j + 1; k < nodes.size(); k++) {
      |                                 ~~^~~~~~~~~~~~~~
supertrees.cpp:64:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             for (int k = 0; k < trees[j].size(); k++) {
      |                             ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:65:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |                 for (int l = k + 1; l < trees[j].size(); l++) {
      |                                     ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:77:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             for (int k = 0; k < trees[j].size() - 1; k++) {
      |                             ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1304 KB Output is correct
7 Correct 161 ms 22120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1304 KB Output is correct
7 Correct 161 ms 22120 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 176 ms 22024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 68 ms 14768 KB Output is correct
18 Correct 0 ms 436 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 44 ms 6236 KB Output is correct
21 Correct 171 ms 24144 KB Output is correct
22 Correct 161 ms 24148 KB Output is correct
23 Correct 165 ms 24008 KB Output is correct
24 Correct 157 ms 24004 KB Output is correct
25 Incorrect 159 ms 24152 KB Answer gives possible 1 while actual possible 0
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 7 ms 1116 KB Output is correct
9 Correct 183 ms 22116 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1100 KB Output is correct
13 Correct 177 ms 22208 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 73 ms 12556 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 45 ms 5716 KB Output is correct
22 Correct 158 ms 21996 KB Output is correct
23 Correct 156 ms 22044 KB Output is correct
24 Correct 160 ms 22008 KB Output is correct
25 Correct 66 ms 12116 KB Output is correct
26 Incorrect 158 ms 22036 KB Answer gives possible 1 while actual possible 0
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 41 ms 5884 KB Output is correct
5 Correct 164 ms 22060 KB Output is correct
6 Correct 161 ms 22096 KB Output is correct
7 Correct 170 ms 22188 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 40 ms 5888 KB Output is correct
10 Correct 173 ms 22100 KB Output is correct
11 Correct 157 ms 22096 KB Output is correct
12 Correct 163 ms 22088 KB Output is correct
13 Correct 1 ms 544 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 40 ms 5724 KB Output is correct
17 Correct 160 ms 22188 KB Output is correct
18 Correct 164 ms 22136 KB Output is correct
19 Correct 158 ms 22060 KB Output is correct
20 Correct 161 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1304 KB Output is correct
7 Correct 161 ms 22120 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 176 ms 22024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 68 ms 14768 KB Output is correct
18 Correct 0 ms 436 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 44 ms 6236 KB Output is correct
21 Correct 171 ms 24144 KB Output is correct
22 Correct 161 ms 24148 KB Output is correct
23 Correct 165 ms 24008 KB Output is correct
24 Correct 157 ms 24004 KB Output is correct
25 Incorrect 159 ms 24152 KB Answer gives possible 1 while actual possible 0
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1304 KB Output is correct
7 Correct 161 ms 22120 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 176 ms 22024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 68 ms 14768 KB Output is correct
18 Correct 0 ms 436 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 44 ms 6236 KB Output is correct
21 Correct 171 ms 24144 KB Output is correct
22 Correct 161 ms 24148 KB Output is correct
23 Correct 165 ms 24008 KB Output is correct
24 Correct 157 ms 24004 KB Output is correct
25 Incorrect 159 ms 24152 KB Answer gives possible 1 while actual possible 0
26 Halted 0 ms 0 KB -