답안 #746085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746085 2023-05-21T11:36:05 Z JakobZorz 슈퍼트리 잇기 (IOI20_supertrees) C++14
56 / 100
237 ms 26048 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;
}

int 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){
                if(tree_ids[j]!=-1)
                    return 0;
                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]]);
    return 1;
}

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++)
        if(connect_group(i)==0)
            return 0;
    
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int 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:81:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   81 |     for(int i=0;i<num_groups;i++)
      |     ^~~
supertrees.cpp:85:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |  build(answer);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1376 KB Output is correct
7 Correct 182 ms 26004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1376 KB Output is correct
7 Correct 182 ms 26004 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 185 ms 26004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 84 ms 16024 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 6788 KB Output is correct
21 Correct 233 ms 26028 KB Output is correct
22 Correct 200 ms 26048 KB Output is correct
23 Correct 196 ms 25980 KB Output is correct
24 Correct 207 ms 26036 KB Output is correct
25 Correct 83 ms 16024 KB Output is correct
26 Correct 107 ms 16024 KB Output is correct
27 Correct 237 ms 26000 KB Output is correct
28 Correct 190 ms 25964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 49 ms 6772 KB Output is correct
5 Correct 194 ms 26004 KB Output is correct
6 Correct 183 ms 25932 KB Output is correct
7 Correct 186 ms 26004 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 48 ms 6800 KB Output is correct
10 Correct 189 ms 26012 KB Output is correct
11 Correct 190 ms 26004 KB Output is correct
12 Correct 196 ms 26004 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 51 ms 6804 KB Output is correct
17 Correct 189 ms 26016 KB Output is correct
18 Correct 186 ms 26012 KB Output is correct
19 Correct 194 ms 26028 KB Output is correct
20 Correct 193 ms 26004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1376 KB Output is correct
7 Correct 182 ms 26004 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 185 ms 26004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 84 ms 16024 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 6788 KB Output is correct
21 Correct 233 ms 26028 KB Output is correct
22 Correct 200 ms 26048 KB Output is correct
23 Correct 196 ms 25980 KB Output is correct
24 Correct 207 ms 26036 KB Output is correct
25 Correct 83 ms 16024 KB Output is correct
26 Correct 107 ms 16024 KB Output is correct
27 Correct 237 ms 26000 KB Output is correct
28 Correct 190 ms 25964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1376 KB Output is correct
7 Correct 182 ms 26004 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1492 KB Output is correct
13 Correct 185 ms 26004 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 84 ms 16024 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 52 ms 6788 KB Output is correct
21 Correct 233 ms 26028 KB Output is correct
22 Correct 200 ms 26048 KB Output is correct
23 Correct 196 ms 25980 KB Output is correct
24 Correct 207 ms 26036 KB Output is correct
25 Correct 83 ms 16024 KB Output is correct
26 Correct 107 ms 16024 KB Output is correct
27 Correct 237 ms 26000 KB Output is correct
28 Correct 190 ms 25964 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -