Submission #309048

# Submission time Handle Problem Language Result Execution time Memory
309048 2020-10-02T16:01:34 Z tjdgus4384 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
287 ms 34168 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector<int> graph[1001], trees[1001];
vector<vector<int> > b, P, newp;
vector<int> v[1001];
vector<int> sametree;
bool visited[1001];
 
void dfs(int x, int cnt){
    graph[cnt].push_back(x);
    for(int i = 0;i < v[x].size();i++){
        if(visited[v[x][i]]) continue;
        visited[v[x][i]] = true;
        dfs(v[x][i], cnt);
    }
}
 
void make_tree(int x){
    for(int i = 0;i < v[x].size();i++){
        if(visited[v[x][i]]) continue;
        if(P[x][v[x][i]] != 1) continue;
        visited[v[x][i]] = true;
        sametree.push_back(v[x][i]);
        make_tree(v[x][i]);
        b[x][v[x][i]] = 1;
        b[v[x][i]][x] = 1;
    }
}

int construct(vector<vector<int> > p){
    P = p;
    b.resize(p.size());
    newp.resize(p.size());
    for(int i = 0;i < p.size();i++){
        b[i].resize(p.size());
        newp[i].resize(p.size());
        for(int j = 0;j < p.size();j++){
            if(i == j) continue;
            if(p[i][j]) v[i].push_back(j);
            if(p[i][j] == 3) return 0;
        }
    }
    int cnt = 0;
    for(int i = 0;i < p.size();i++){
        if(visited[i]) continue;
        visited[i] = true;
        dfs(i, cnt); cnt++;
    }
    for(int i = 0;i < p.size();i++) visited[i] = false;
    for(int i = 0;i < cnt;i++){
        vector<int> nv;
        for(int j = 0;j < graph[i].size();j++){
            if(visited[graph[i][j]]) continue;
            visited[graph[i][j]] = true;
            sametree.push_back(graph[i][j]);
            make_tree(graph[i][j]);
            for(int x1 = 0;x1 < sametree.size();x1++){
                for(int x2 = 0;x2 < sametree.size();x2++){
                    if(x1 == x2) continue;
                    newp[sametree[x1]][sametree[x2]] = newp[sametree[x2]][sametree[x1]] = 1;
                }
            }
            sametree.clear();
            nv.push_back(graph[i][j]);
        }
        if(nv.size() <= 1) continue;
        if(nv.size() <= 2) return 0;
        for(int j = 0;j < nv.size() - 1;j++){
            b[nv[j]][nv[j+1]] = 1;
            b[nv[j+1]][nv[j]] = 1;
        }
        for(int x1 = 0;x1 < nv.size();x1++){
            for(int x2 = 0;x2 < graph[i].size();x2++){
                if(nv[x1] == graph[i][x2]) continue;
                if(newp[nv[x1]][graph[i][x2]]) continue;
                newp[nv[x1]][graph[i][x2]] = newp[graph[i][x2]][nv[x1]] = 2;
            }
        }
        for(int x1 = 0;x1 < graph[i].size();x1++){
            for(int x2 = 0;x2 < graph[i].size();x2++){
                if(graph[i][x1] == graph[i][x2]) continue;
                if(newp[graph[i][x1]][graph[i][x2]]) continue;
                newp[graph[i][x1]][graph[i][x2]] = newp[graph[i][x2]][graph[i][x1]] = 2;
            }
        }
        b[nv[0]][nv.back()] = 1;
        b[nv.back()][nv[0]] = 1;
    }
    for(int i = 0;i < p.size();i++){
        for(int j = 0;j < p.size();j++){
            if(i == j) continue;
            if(p[i][j] != newp[i][j]) return 0;
        }
    }
    build(b);
    return 1;
}

Compilation message

supertrees.cpp: In function 'void dfs(int, int)':
supertrees.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0;i < v[x].size();i++){
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'void make_tree(int)':
supertrees.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0;i < v[x].size();i++){
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int j = 0;j < p.size();j++){
      |                       ~~^~~~~~~~~~
supertrees.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0;i < p.size();i++) visited[i] = false;
      |                   ~~^~~~~~~~~~
supertrees.cpp:53:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int j = 0;j < graph[i].size();j++){
      |                       ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             for(int x1 = 0;x1 < sametree.size();x1++){
      |                            ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:59:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |                 for(int x2 = 0;x2 < sametree.size();x2++){
      |                                ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:69:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int j = 0;j < nv.size() - 1;j++){
      |                       ~~^~~~~~~~~~~~~~~
supertrees.cpp:73:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int x1 = 0;x1 < nv.size();x1++){
      |                        ~~~^~~~~~~~~~~
supertrees.cpp:74:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             for(int x2 = 0;x2 < graph[i].size();x2++){
      |                            ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:80:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(int x1 = 0;x1 < graph[i].size();x1++){
      |                        ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:81:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |             for(int x2 = 0;x2 < graph[i].size();x2++){
      |                            ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:90:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for(int i = 0;i < p.size();i++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:91:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         for(int j = 0;j < p.size();j++){
      |                       ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1920 KB Output is correct
7 Correct 287 ms 34168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1920 KB Output is correct
7 Correct 287 ms 34168 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1664 KB Output is correct
13 Correct 258 ms 30072 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 149 ms 22648 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 64 ms 7928 KB Output is correct
21 Correct 263 ms 30712 KB Output is correct
22 Correct 257 ms 30072 KB Output is correct
23 Correct 276 ms 32120 KB Output is correct
24 Correct 253 ms 30244 KB Output is correct
25 Correct 117 ms 20600 KB Output is correct
26 Correct 108 ms 20216 KB Output is correct
27 Correct 275 ms 33144 KB Output is correct
28 Correct 252 ms 30072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 11 ms 1664 KB Output is correct
9 Correct 247 ms 30248 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 12 ms 1792 KB Output is correct
13 Correct 280 ms 34168 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 136 ms 22560 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 65 ms 7928 KB Output is correct
22 Correct 257 ms 30584 KB Output is correct
23 Correct 251 ms 30072 KB Output is correct
24 Correct 275 ms 33184 KB Output is correct
25 Correct 109 ms 20216 KB Output is correct
26 Correct 113 ms 20636 KB Output is correct
27 Correct 251 ms 30072 KB Output is correct
28 Correct 262 ms 32120 KB Output is correct
29 Correct 103 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 64 ms 7932 KB Output is correct
5 Correct 249 ms 30712 KB Output is correct
6 Correct 240 ms 30072 KB Output is correct
7 Correct 264 ms 32120 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 62 ms 7928 KB Output is correct
10 Correct 259 ms 30712 KB Output is correct
11 Correct 241 ms 30116 KB Output is correct
12 Correct 262 ms 33144 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 64 ms 8056 KB Output is correct
17 Correct 252 ms 30584 KB Output is correct
18 Correct 251 ms 30712 KB Output is correct
19 Correct 249 ms 30328 KB Output is correct
20 Correct 242 ms 30072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1920 KB Output is correct
7 Correct 287 ms 34168 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1664 KB Output is correct
13 Correct 258 ms 30072 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 149 ms 22648 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 64 ms 7928 KB Output is correct
21 Correct 263 ms 30712 KB Output is correct
22 Correct 257 ms 30072 KB Output is correct
23 Correct 276 ms 32120 KB Output is correct
24 Correct 253 ms 30244 KB Output is correct
25 Correct 117 ms 20600 KB Output is correct
26 Correct 108 ms 20216 KB Output is correct
27 Correct 275 ms 33144 KB Output is correct
28 Correct 252 ms 30072 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 1664 KB Output is correct
37 Correct 247 ms 30248 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 1792 KB Output is correct
41 Correct 280 ms 34168 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1280 KB Output is correct
45 Correct 136 ms 22560 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 65 ms 7928 KB Output is correct
50 Correct 257 ms 30584 KB Output is correct
51 Correct 251 ms 30072 KB Output is correct
52 Correct 275 ms 33184 KB Output is correct
53 Correct 109 ms 20216 KB Output is correct
54 Correct 113 ms 20636 KB Output is correct
55 Correct 251 ms 30072 KB Output is correct
56 Correct 262 ms 32120 KB Output is correct
57 Correct 103 ms 20216 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 6 ms 1408 KB Output is correct
61 Correct 138 ms 24380 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 62 ms 7932 KB Output is correct
66 Correct 110 ms 20728 KB Output is correct
67 Correct 110 ms 20600 KB Output is correct
68 Correct 107 ms 20344 KB Output is correct
69 Correct 106 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 1920 KB Output is correct
7 Correct 287 ms 34168 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1664 KB Output is correct
13 Correct 258 ms 30072 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 149 ms 22648 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 64 ms 7928 KB Output is correct
21 Correct 263 ms 30712 KB Output is correct
22 Correct 257 ms 30072 KB Output is correct
23 Correct 276 ms 32120 KB Output is correct
24 Correct 253 ms 30244 KB Output is correct
25 Correct 117 ms 20600 KB Output is correct
26 Correct 108 ms 20216 KB Output is correct
27 Correct 275 ms 33144 KB Output is correct
28 Correct 252 ms 30072 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 1664 KB Output is correct
37 Correct 247 ms 30248 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 12 ms 1792 KB Output is correct
41 Correct 280 ms 34168 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1280 KB Output is correct
45 Correct 136 ms 22560 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 65 ms 7928 KB Output is correct
50 Correct 257 ms 30584 KB Output is correct
51 Correct 251 ms 30072 KB Output is correct
52 Correct 275 ms 33184 KB Output is correct
53 Correct 109 ms 20216 KB Output is correct
54 Correct 113 ms 20636 KB Output is correct
55 Correct 251 ms 30072 KB Output is correct
56 Correct 262 ms 32120 KB Output is correct
57 Correct 103 ms 20216 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 64 ms 7932 KB Output is correct
62 Correct 249 ms 30712 KB Output is correct
63 Correct 240 ms 30072 KB Output is correct
64 Correct 264 ms 32120 KB Output is correct
65 Correct 0 ms 384 KB Output is correct
66 Correct 62 ms 7928 KB Output is correct
67 Correct 259 ms 30712 KB Output is correct
68 Correct 241 ms 30116 KB Output is correct
69 Correct 262 ms 33144 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 64 ms 8056 KB Output is correct
74 Correct 252 ms 30584 KB Output is correct
75 Correct 251 ms 30712 KB Output is correct
76 Correct 249 ms 30328 KB Output is correct
77 Correct 242 ms 30072 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 6 ms 1408 KB Output is correct
81 Correct 138 ms 24380 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 0 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 62 ms 7932 KB Output is correct
86 Correct 110 ms 20728 KB Output is correct
87 Correct 110 ms 20600 KB Output is correct
88 Correct 107 ms 20344 KB Output is correct
89 Correct 106 ms 20216 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 5 ms 896 KB Output is correct
93 Correct 106 ms 12412 KB Output is correct
94 Correct 0 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 0 ms 384 KB Output is correct
97 Correct 25 ms 3584 KB Output is correct
98 Correct 97 ms 12792 KB Output is correct
99 Correct 99 ms 13504 KB Output is correct
100 Correct 96 ms 12920 KB Output is correct
101 Correct 100 ms 14968 KB Output is correct
102 Correct 105 ms 12280 KB Output is correct
103 Correct 106 ms 12320 KB Output is correct
104 Correct 106 ms 12280 KB Output is correct
105 Correct 106 ms 12408 KB Output is correct