Submission #313163

# Submission time Handle Problem Language Result Execution time Memory
313163 2020-10-15T10:21:00 Z wasyl Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
298 ms 22392 KB
#include "supertrees.h"
#include <vector>
using namespace std;

int construct(std::vector<std::vector<int>> p) {
    //int n = p.size();
    //std::vector<std::vector<int>> answer;
    //for (int i = 0; i < n; i++) {
    //	std::vector<int> row;
    //	row.resize(n);
    //	answer.push_back(row);
    //}
    //build(answer);
    //return 1;


    int n = p.size();
    vector< vector< int > > ans(n, vector< int >(n));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            if (p[i][j] == 3)
                return 0;

    vector< int > siv(n, false);

    vector< int > vis(n, false);
    for (int i = 0; i < n; ++i)
        if (not vis[i])
        {
            vector< int > sub;
            for (int j = 0; j < n; ++j)
                if (p[i][j] and not vis[j])
                    sub.push_back(j);
                else if (p[i][j] and vis[j]) return 0;

            for (int a : sub)
                vis[a] = true;

            for (int a : sub)
                for (int j = 0; j < n; ++j)
                    if (not vis[j] and p[a][j])
                        return 0;

            for (int a : sub)
                for (int b : sub)
                    if (not p[a][b])
                        return 0;
            
                
            vector< vector< int > > div;
            for (int a : sub)
                if (not siv[a])
                {
                    div.push_back(vector< int >());
                    for (int b : sub)
                        if (p[a][b] == 1 and not siv[b])
                            div.back().push_back(b);
                        else if (p[a][b] == 1 and siv[b]) return 0;

                    for (int a : div.back())
                        siv[a] = true;

                    for (int a : div.back())
                        for (int b : sub)
                            if (not siv[b] and p[a][b] == 1)
                                return 0;

                    for (int a : div.back())
                        for (int b : div.back())
                            if (p[a][b] != 1)
                                return 0;
                }

            for (int i = 1; i < div.size(); ++i)
                ans[div[i - 1][0]][div[i][0]] = ans[div[i][0]][div[i - 1][0]] = 1;
                
            if (div.size() > 1)
                ans[div.back()[0]][div.front()[0]] = ans[div.front()[0]][div.back()[0]] = 1;

            for (const auto& vv : div)
                for (int i = 1; i < vv.size(); ++i)
                    ans[vv[i]][vv[i - 1]] = ans[vv[i - 1]][vv[i]] = 1;
        }

    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:74:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             for (int i = 1; i < div.size(); ++i)
      |                             ~~^~~~~~~~~~~~
supertrees.cpp:81:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                 for (int i = 1; i < vv.size(); ++i)
      |                                 ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 288 ms 22392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 288 ms 22392 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 287 ms 22008 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 108 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 72 ms 5752 KB Output is correct
21 Correct 287 ms 22136 KB Output is correct
22 Correct 298 ms 22136 KB Output is correct
23 Correct 292 ms 22264 KB Output is correct
24 Correct 290 ms 22136 KB Output is correct
25 Correct 109 ms 12152 KB Output is correct
26 Correct 101 ms 12152 KB Output is correct
27 Correct 289 ms 22136 KB Output is correct
28 Correct 286 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 72 ms 5752 KB Output is correct
5 Correct 291 ms 22136 KB Output is correct
6 Correct 284 ms 22136 KB Output is correct
7 Correct 298 ms 22136 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 71 ms 5752 KB Output is correct
10 Correct 284 ms 22136 KB Output is correct
11 Correct 283 ms 22136 KB Output is correct
12 Correct 290 ms 22136 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 73 ms 5752 KB Output is correct
17 Correct 285 ms 22136 KB Output is correct
18 Correct 284 ms 22136 KB Output is correct
19 Correct 283 ms 22136 KB Output is correct
20 Correct 284 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 288 ms 22392 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 287 ms 22008 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 108 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 72 ms 5752 KB Output is correct
21 Correct 287 ms 22136 KB Output is correct
22 Correct 298 ms 22136 KB Output is correct
23 Correct 292 ms 22264 KB Output is correct
24 Correct 290 ms 22136 KB Output is correct
25 Correct 109 ms 12152 KB Output is correct
26 Correct 101 ms 12152 KB Output is correct
27 Correct 289 ms 22136 KB Output is correct
28 Correct 286 ms 22136 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 288 ms 22392 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 287 ms 22008 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 108 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 72 ms 5752 KB Output is correct
21 Correct 287 ms 22136 KB Output is correct
22 Correct 298 ms 22136 KB Output is correct
23 Correct 292 ms 22264 KB Output is correct
24 Correct 290 ms 22136 KB Output is correct
25 Correct 109 ms 12152 KB Output is correct
26 Correct 101 ms 12152 KB Output is correct
27 Correct 289 ms 22136 KB Output is correct
28 Correct 286 ms 22136 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -