Submission #746083

# Submission time Handle Problem Language Result Execution time Memory
746083 2023-05-21T11:33:56 Z JakobZorz Connecting Supertrees (IOI20_supertrees) C++14
56 / 100
230 ms 28076 KB
#include "supertrees.h"
#include <vector>
using namespace std;

vector<vector<int>> answer;
int group_ids[1000];
vector<int> groups[1000];
vector<vector<int>> p;
int num_groups;

void connect(int a, int b){
    answer[a][b]=1;
    answer[b][a]=1;
}

void connect_group(int group_id){
    vector<int> group=groups[group_id];
    vector<bool> in_cycle(group.size(),false);
    vector<int> tree_ids(group.size(),-1);
    vector<int> trees[1000];
    
    int num_trees=0;
    for(int i=0;i<group.size();i++){
        if(tree_ids[i]!=-1)
            continue;
        tree_ids[i]=num_trees;
        trees[num_trees].push_back(i);
        for(int j=0;j<group.size();j++){
            if(i!=j&&p[group[i]][group[j]]==1){
                tree_ids[j]=num_trees;
                trees[num_trees].push_back(j);
                connect(group[i],group[j]);
            }
        }
        num_trees++;
    }
    
    for(int i=0;i<num_trees-1;i++)
        connect(group[trees[i][0]],group[trees[i+1][0]]);
    if(num_trees!=1)
        connect(group[trees[0][0]],group[trees[num_trees-1][0]]);
}

int construct(vector<vector<int>> p_) {
    p=p_;
    int n = p.size();
    answer=vector<vector<int>>(n,vector<int>(n,0));
    for(vector<int>& i:p)
        for(int j:i)
            if(j==3)
                return 0;
    for(int i=0;i<n;i++)
        group_ids[i]=-1;
    
    for(int i=0;i<n;i++){
        if(group_ids[i]!=-1)
            continue;
        
        group_ids[i]=num_groups;
        groups[num_groups].push_back(i);
        for(int j=i+1;j<n;j++){
            if(p[i][j]!=0){
                group_ids[j]=num_groups;
                groups[num_groups].push_back(j);
            }
        }
        num_groups++;
    }
    
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++){
            if(group_ids[i]!=group_ids[j]&&p[i][j]!=0)
                return 0;
            if(group_ids[i]==group_ids[j]&&p[i][j]==0)
                return 0;
        }
    
    for(int i=0;i<num_groups;i++)
        connect_group(i);
    
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void connect_group(int)':
supertrees.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<group.size();i++){
      |                 ~^~~~~~~~~~~~~
supertrees.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int j=0;j<group.size();j++){
      |                     ~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   78 |     for(int i=0;i<num_groups;i++)
      |     ^~~
supertrees.cpp:81:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   81 |  build(answer);
      |  ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 10 ms 1344 KB Output is correct
7 Correct 183 ms 26004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 10 ms 1344 KB Output is correct
7 Correct 183 ms 26004 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 9 ms 1364 KB Output is correct
13 Correct 201 ms 26032 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 84 ms 16028 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 6732 KB Output is correct
21 Correct 208 ms 25972 KB Output is correct
22 Correct 189 ms 26060 KB Output is correct
23 Correct 186 ms 26016 KB Output is correct
24 Correct 189 ms 26064 KB Output is correct
25 Correct 87 ms 16024 KB Output is correct
26 Correct 90 ms 16032 KB Output is correct
27 Correct 220 ms 26016 KB Output is correct
28 Correct 187 ms 25996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 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 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 58 ms 6792 KB Output is correct
5 Correct 191 ms 26132 KB Output is correct
6 Correct 199 ms 25932 KB Output is correct
7 Correct 189 ms 25956 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 50 ms 6760 KB Output is correct
10 Correct 213 ms 26052 KB Output is correct
11 Correct 191 ms 26004 KB Output is correct
12 Correct 182 ms 26016 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 48 ms 7244 KB Output is correct
17 Correct 203 ms 27908 KB Output is correct
18 Correct 230 ms 27912 KB Output is correct
19 Correct 185 ms 28052 KB Output is correct
20 Correct 204 ms 28076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 10 ms 1344 KB Output is correct
7 Correct 183 ms 26004 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 9 ms 1364 KB Output is correct
13 Correct 201 ms 26032 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 84 ms 16028 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 6732 KB Output is correct
21 Correct 208 ms 25972 KB Output is correct
22 Correct 189 ms 26060 KB Output is correct
23 Correct 186 ms 26016 KB Output is correct
24 Correct 189 ms 26064 KB Output is correct
25 Correct 87 ms 16024 KB Output is correct
26 Correct 90 ms 16032 KB Output is correct
27 Correct 220 ms 26016 KB Output is correct
28 Correct 187 ms 25996 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 10 ms 1344 KB Output is correct
7 Correct 183 ms 26004 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 9 ms 1364 KB Output is correct
13 Correct 201 ms 26032 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 84 ms 16028 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 6732 KB Output is correct
21 Correct 208 ms 25972 KB Output is correct
22 Correct 189 ms 26060 KB Output is correct
23 Correct 186 ms 26016 KB Output is correct
24 Correct 189 ms 26064 KB Output is correct
25 Correct 87 ms 16024 KB Output is correct
26 Correct 90 ms 16032 KB Output is correct
27 Correct 220 ms 26016 KB Output is correct
28 Correct 187 ms 25996 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -