답안 #746074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746074 2023-05-21T11:18:08 Z JakobZorz 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
205 ms 27924 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);
    int present2=-1;
    for(int i=0;i<group.size();i++){
        for(int j=0;j<group.size();j++){
            if(p[group[i]][group[j]]==2){
                present2=j;
            }
        }
    }
    
    if(present2==-1){
        for(int i=0;i<group.size()-1;i++){
            connect(group[i],group[i+1]);
        }
        return;
    }
    
    vector<int> cycle;
    in_cycle[present2]=true;
    for(int i=0;i<group.size();i++){
        bool valid=true;
        for(int j=0;j<cycle.size();j++){
            if(p[group[cycle[j]]][group[i]]!=2){
                valid=false;
                break;
            }
        }
        
        if(valid){
            cycle.push_back(i);
            in_cycle[i]=true;
        }
    }
    
    for(int i=0;i<cycle.size()-1;i++)
        connect(group[cycle[i]],group[cycle[i+1]]);
    connect(group[cycle[0]],group[cycle.back()]);
    
    for(int i=0;i<group.size();i++){
        if(in_cycle[i])
            continue;
        for(int j=0;j<group.size();j++){
            if(i!=j&&p[group[i]][group[j]]==1&&in_cycle[group[j]]){
                connect(group[i],group[j]);
            }
        }
    }
}

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:20:18: 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<group.size();i++){
      |                 ~^~~~~~~~~~~~~
supertrees.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int j=0;j<group.size();j++){
      |                     ~^~~~~~~~~~~~~
supertrees.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i=0;i<group.size()-1;i++){
      |                     ~^~~~~~~~~~~~~~~
supertrees.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0;i<group.size();i++){
      |                 ~^~~~~~~~~~~~~
supertrees.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int j=0;j<cycle.size();j++){
      |                     ~^~~~~~~~~~~~~
supertrees.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<cycle.size()-1;i++)
      |                 ~^~~~~~~~~~~~~~~
supertrees.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i=0;i<group.size();i++){
      |                 ~^~~~~~~~~~~~~
supertrees.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int j=0;j<group.size();j++){
      |                     ~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:101:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  101 |     for(int i=0;i<num_groups;i++)
      |     ^~~
supertrees.cpp:104:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  104 |  build(answer);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1364 KB Output is correct
7 Correct 182 ms 25988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1364 KB Output is correct
7 Correct 182 ms 25988 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1376 KB Output is correct
13 Correct 184 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 940 KB Output is correct
17 Correct 86 ms 18048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 312 KB Output is correct
20 Correct 47 ms 7172 KB Output is correct
21 Correct 205 ms 27908 KB Output is correct
22 Correct 191 ms 27904 KB Output is correct
23 Correct 190 ms 27916 KB Output is correct
24 Correct 182 ms 27924 KB Output is correct
25 Correct 81 ms 18048 KB Output is correct
26 Correct 82 ms 18064 KB Output is correct
27 Correct 189 ms 27920 KB Output is correct
28 Correct 186 ms 27920 KB Output is correct
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 48 ms 6772 KB Output is correct
5 Correct 196 ms 26004 KB Output is correct
6 Correct 192 ms 26020 KB Output is correct
7 Correct 190 ms 26016 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 47 ms 6656 KB Output is correct
10 Correct 181 ms 25996 KB Output is correct
11 Correct 187 ms 26004 KB Output is correct
12 Correct 183 ms 25960 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Too few ways to get from 0 to 4, should be 1 found 0
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1364 KB Output is correct
7 Correct 182 ms 25988 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1376 KB Output is correct
13 Correct 184 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 940 KB Output is correct
17 Correct 86 ms 18048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 312 KB Output is correct
20 Correct 47 ms 7172 KB Output is correct
21 Correct 205 ms 27908 KB Output is correct
22 Correct 191 ms 27904 KB Output is correct
23 Correct 190 ms 27916 KB Output is correct
24 Correct 182 ms 27924 KB Output is correct
25 Correct 81 ms 18048 KB Output is correct
26 Correct 82 ms 18064 KB Output is correct
27 Correct 189 ms 27920 KB Output is correct
28 Correct 186 ms 27920 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1364 KB Output is correct
7 Correct 182 ms 25988 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1376 KB Output is correct
13 Correct 184 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 940 KB Output is correct
17 Correct 86 ms 18048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 312 KB Output is correct
20 Correct 47 ms 7172 KB Output is correct
21 Correct 205 ms 27908 KB Output is correct
22 Correct 191 ms 27904 KB Output is correct
23 Correct 190 ms 27916 KB Output is correct
24 Correct 182 ms 27924 KB Output is correct
25 Correct 81 ms 18048 KB Output is correct
26 Correct 82 ms 18064 KB Output is correct
27 Correct 189 ms 27920 KB Output is correct
28 Correct 186 ms 27920 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 -