Submission #1016000

# Submission time Handle Problem Language Result Execution time Memory
1016000 2024-07-07T08:52:27 Z deera Connecting Supertrees (IOI20_supertrees) C++14
40 / 100
157 ms 27476 KB
#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;

int construct(vector<vector<int>> p) {
    int n = p.size();
    vector<int> dist = {0, 0, 0, 0};

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            dist[p[i][j]]++;

    // subtask 1
    // p[i][j] ==0
    // just a line
    if (dist[1] == n*n) {
        vector<vector<int>> r(n, vector<int>(n));
        for(int i=0;i<n-1;i++) {
            r[i][(i+1)%n] = 1;
            r[(i+1)%n][i] = 1;
        }

        build(r);
        return 1;
    }

    // substask 2
    // p[i][j] == 0 or 1
    // set of disconnected lines
    if(dist[2] == 0 && dist[3] == 0) {
        set<vector<int>> lines;

        for(int i=0;i<n;i++) {
            lines.insert(p[i]);
        }



        vector<vector<int>> r(n, vector<int>(n));
        vector<int> dupes(n);

        for (auto line: lines) {
            vector<int> points;
            for(int i=0;i<n;i++)
                if (line[i] == 1) 
                    points.push_back(i), dupes[i]++;

            for(int i=1;i<points.size();i++) {
                int a = points[i-1], b=points[i];

                r[a][b] = 1;
                r[b][a] = 1;
            }
        }

        for(auto i: dupes) 
            if (i > 1) return 0;

        build(r);
        return 1;
    }

    // substask 3
    // p[i][j] == 0 or 2 (except for i==j)
    // set of disconnected rings
    if(dist[1] == n && dist[3] == 0) {
        set<vector<int>> lines;

        for(int i=0;i<n;i++) {
            vector<int> line(n);
            for(int j=0;j<n;j++) {
                if (i == j && p[i][j] != 1) {
                    return 0;
                }
                line[j] = (int)(p[i][j] > 0);
            }
            lines.insert(line);
        }



        vector<vector<int>> r(n, vector<int>(n));
        vector<int> dupes(n);

        for (auto line: lines) {
            vector<int> points;
            for(int i=0;i<n;i++)
                if (line[i] == 1) 
                    points.push_back(i), dupes[i]++;

            // single point not connected to anything
            // (except itself)
            if (points.size() == 1) {
                continue;
            }
            
            // you need atleast 3 nodes to make a ring
            // without having multiple edges between 
            // two nodes
            if (points.size() < 3) {
                return 0;
            }

            for(int i=1;i<points.size();i++) {
                int a = points[i-1], b=points[i];

                r[a][b] = 1;
                r[b][a] = 1;
            }

            int a = points[0], b=points.back();
            r[a][b] = 1;
            r[b][a] = 1;
        }

        for(auto i: dupes) 
            if (i > 1) return 0;

        build(r);
        return 1;

    }

    return 0;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             for(int i=1;i<points.size();i++) {
      |                         ~^~~~~~~~~~~~~~
supertrees.cpp:105:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |             for(int i=1;i<points.size();i++) {
      |                         ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 5 ms 1188 KB Output is correct
7 Correct 106 ms 23272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 5 ms 1188 KB Output is correct
7 Correct 106 ms 23272 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 124 ms 27476 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 66 ms 17552 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6520 KB Output is correct
21 Correct 116 ms 23284 KB Output is correct
22 Correct 121 ms 24916 KB Output is correct
23 Correct 119 ms 23376 KB Output is correct
24 Correct 119 ms 27216 KB Output is correct
25 Correct 55 ms 13472 KB Output is correct
26 Correct 55 ms 14928 KB Output is correct
27 Correct 120 ms 23376 KB Output is correct
28 Correct 121 ms 27168 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1444 KB Output is correct
9 Correct 120 ms 27256 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1188 KB Output is correct
13 Correct 113 ms 23380 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 68 ms 17308 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 29 ms 6744 KB Output is correct
22 Correct 115 ms 24056 KB Output is correct
23 Correct 121 ms 24704 KB Output is correct
24 Correct 121 ms 23948 KB Output is correct
25 Correct 59 ms 17832 KB Output is correct
26 Correct 54 ms 14088 KB Output is correct
27 Correct 115 ms 24916 KB Output is correct
28 Correct 119 ms 24148 KB Output is correct
29 Correct 58 ms 18004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 29 ms 6408 KB Output is correct
5 Correct 119 ms 23892 KB Output is correct
6 Correct 115 ms 25428 KB Output is correct
7 Correct 120 ms 23772 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 29 ms 6328 KB Output is correct
10 Correct 116 ms 24148 KB Output is correct
11 Correct 127 ms 24912 KB Output is correct
12 Correct 157 ms 24148 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 5 ms 1188 KB Output is correct
7 Correct 106 ms 23272 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 124 ms 27476 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 66 ms 17552 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6520 KB Output is correct
21 Correct 116 ms 23284 KB Output is correct
22 Correct 121 ms 24916 KB Output is correct
23 Correct 119 ms 23376 KB Output is correct
24 Correct 119 ms 27216 KB Output is correct
25 Correct 55 ms 13472 KB Output is correct
26 Correct 55 ms 14928 KB Output is correct
27 Correct 120 ms 23376 KB Output is correct
28 Correct 121 ms 27168 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1444 KB Output is correct
37 Correct 120 ms 27256 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1188 KB Output is correct
41 Correct 113 ms 23380 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 68 ms 17308 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 29 ms 6744 KB Output is correct
50 Correct 115 ms 24056 KB Output is correct
51 Correct 121 ms 24704 KB Output is correct
52 Correct 121 ms 23948 KB Output is correct
53 Correct 59 ms 17832 KB Output is correct
54 Correct 54 ms 14088 KB Output is correct
55 Correct 115 ms 24916 KB Output is correct
56 Correct 119 ms 24148 KB Output is correct
57 Correct 58 ms 18004 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 604 KB Output is correct
61 Correct 53 ms 10216 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Incorrect 0 ms 344 KB Answer gives possible 0 while actual possible 1
64 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 5 ms 1188 KB Output is correct
7 Correct 106 ms 23272 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 124 ms 27476 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 66 ms 17552 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6520 KB Output is correct
21 Correct 116 ms 23284 KB Output is correct
22 Correct 121 ms 24916 KB Output is correct
23 Correct 119 ms 23376 KB Output is correct
24 Correct 119 ms 27216 KB Output is correct
25 Correct 55 ms 13472 KB Output is correct
26 Correct 55 ms 14928 KB Output is correct
27 Correct 120 ms 23376 KB Output is correct
28 Correct 121 ms 27168 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1444 KB Output is correct
37 Correct 120 ms 27256 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1188 KB Output is correct
41 Correct 113 ms 23380 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 1116 KB Output is correct
45 Correct 68 ms 17308 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 29 ms 6744 KB Output is correct
50 Correct 115 ms 24056 KB Output is correct
51 Correct 121 ms 24704 KB Output is correct
52 Correct 121 ms 23948 KB Output is correct
53 Correct 59 ms 17832 KB Output is correct
54 Correct 54 ms 14088 KB Output is correct
55 Correct 115 ms 24916 KB Output is correct
56 Correct 119 ms 24148 KB Output is correct
57 Correct 58 ms 18004 KB Output is correct
58 Correct 0 ms 360 KB Output is correct
59 Correct 0 ms 436 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 29 ms 6408 KB Output is correct
62 Correct 119 ms 23892 KB Output is correct
63 Correct 115 ms 25428 KB Output is correct
64 Correct 120 ms 23772 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 29 ms 6328 KB Output is correct
67 Correct 116 ms 24148 KB Output is correct
68 Correct 127 ms 24912 KB Output is correct
69 Correct 157 ms 24148 KB Output is correct
70 Correct 1 ms 600 KB Output is correct
71 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
72 Halted 0 ms 0 KB -