답안 #733783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733783 2023-05-01T09:52:03 Z tigar 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
213 ms 24176 KB
#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;

typedef long long ll;
vector<int> jedan[1010], dva[1010], nula[1010];
bool check[1010];
vector<int>lin;
vector<int>cc[1010];
int linije[1010], komponente[1010];

int construct(std::vector<std::vector<int>>p)
{
    int n=p.size();
    int br=1;

    for(int i=0; i<n; i++)linije[i]=-1;
    for(int i=0; i<n; i++)
    {
        if(!check[i])
        {
            check[i]=true;
            lin.push_back(i);
            linije[i]=i;
            bool z=false, g=false;
            for(int j=0; j<n; j++)
            {
                if(!z and p[i][j]!=0)
                {
                    z=true;
                    if(komponente[j]!=0 and komponente[i]==0){komponente[i]=komponente[j];}
                    else if(komponente[j]!=0 and komponente[i]!=0 and komponente[i]!=komponente[j])return 0;
                    else if(komponente[j]==0){komponente[i]=br; g=true; br++;}
                    cc[komponente[i]].push_back(i);
                }
                if(p[i][j]==1)
                {
                    if(linije[j]!=-1 and linije[i]!=linije[j])return 0;
                    linije[j]=i; check[j]=true;
                    if(komponente[j]!=0 and komponente[j]!=komponente[i])return 0;
                    komponente[j]=komponente[i];
                    jedan[i].push_back(j);
                }
                else if(p[i][j]==2)
                {
                    if(komponente[j]!=0 and komponente[j]!=komponente[i])return 0;
                    if(!g and komponente[j]==0)return 0;
                    komponente[j]=komponente[i];
                }
                else if(p[i][j]==3)return 0;
                else if(p[i][j]==0)
                {
                    if(komponente[i]==komponente[j])return 0;
                    if(linije[i]==linije[j])return 0;
                }
            }
        }
        else
        {
            for(int j=0; j<n; j++)
            {
                if(p[i][j]!=p[linije[i]][j])return 0;
            }
        }
    }

    ///ovde pocinje deo za odgovor, njega sredjujem posle
    vector<vector<int> > ans(n);
    for(int i=0; i<n; i++){ans[i].resize(n, 0);}
    for(int i=0; i<lin.size(); i++)
    {
        for(int j=1; j<jedan[lin[i]].size(); j++)
        {
            ans[jedan[lin[i]][j]][jedan[lin[i]][j-1]]=1;
            ans[jedan[lin[i]][j-1]][jedan[lin[i]][j]]=1;
        }
    }

    for(int i=1; i<=br; i++)
    {
        for(int j=0; j<cc[i].size(); j++)
        {
            //cout<<cc[i][j]<<" ";
            if(cc[i].size()==2)return 0;
            ans[cc[i][j]][cc[i][(j+1)%cc[i].size()]]=1;
            ans[cc[i][(j+1)%cc[i].size()]][cc[i][j]]=1;
        }
        //cout<<endl;
    }
    for(int i=0; i<n; i++)
    {
        ans[i][i]=0;
    }
    //for(int i=0; i<n; i++){for(int j=0; j<n; j++)cout<<ans[i][j]<<" "; cout<<endl;}
    build(ans);
    return 1;
}

/*int main()
{
    int n; cin>>n;
    vector<vector<int> >p;
    for(int i=0; i<n; i++)
    {
        vector<int>pp(n);
        for(int j=0; j<n; j++)
        {
            cin>>pp[j];
        }
        p.push_back(pp);
    }
    cout<<construct(p);
}/*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i=0; i<lin.size(); i++)
      |                  ~^~~~~~~~~~~
supertrees.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int j=1; j<jedan[lin[i]].size(); j++)
      |                      ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for(int j=0; j<cc[i].size(); j++)
      |                      ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 176 ms 22180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 176 ms 22180 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 175 ms 22120 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 76 ms 8268 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 42 ms 5864 KB Output is correct
21 Correct 182 ms 22128 KB Output is correct
22 Correct 168 ms 22092 KB Output is correct
23 Correct 189 ms 22124 KB Output is correct
24 Correct 168 ms 22092 KB Output is correct
25 Correct 81 ms 8164 KB Output is correct
26 Correct 76 ms 8396 KB Output is correct
27 Correct 171 ms 22156 KB Output is correct
28 Correct 190 ms 22156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 9 ms 1264 KB Output is correct
9 Correct 176 ms 22220 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 9 ms 1236 KB Output is correct
13 Correct 189 ms 22212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 83 ms 8176 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 400 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 47 ms 6352 KB Output is correct
22 Correct 213 ms 24176 KB Output is correct
23 Correct 185 ms 24152 KB Output is correct
24 Correct 209 ms 24108 KB Output is correct
25 Correct 78 ms 14180 KB Output is correct
26 Correct 79 ms 10196 KB Output is correct
27 Correct 197 ms 24152 KB Output is correct
28 Correct 188 ms 24152 KB Output is correct
29 Correct 76 ms 14292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 43 ms 5836 KB Output is correct
5 Correct 196 ms 22116 KB Output is correct
6 Correct 174 ms 22092 KB Output is correct
7 Correct 195 ms 22092 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 46 ms 5964 KB Output is correct
10 Correct 176 ms 22176 KB Output is correct
11 Correct 171 ms 22084 KB Output is correct
12 Correct 196 ms 22128 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 49 ms 5864 KB Output is correct
17 Correct 178 ms 22140 KB Output is correct
18 Correct 177 ms 22128 KB Output is correct
19 Correct 182 ms 22108 KB Output is correct
20 Correct 183 ms 22132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 176 ms 22180 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 175 ms 22120 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 76 ms 8268 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 42 ms 5864 KB Output is correct
21 Correct 182 ms 22128 KB Output is correct
22 Correct 168 ms 22092 KB Output is correct
23 Correct 189 ms 22124 KB Output is correct
24 Correct 168 ms 22092 KB Output is correct
25 Correct 81 ms 8164 KB Output is correct
26 Correct 76 ms 8396 KB Output is correct
27 Correct 171 ms 22156 KB Output is correct
28 Correct 190 ms 22156 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 1264 KB Output is correct
37 Correct 176 ms 22220 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 9 ms 1236 KB Output is correct
41 Correct 189 ms 22212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 596 KB Output is correct
45 Correct 83 ms 8176 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 400 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6352 KB Output is correct
50 Correct 213 ms 24176 KB Output is correct
51 Correct 185 ms 24152 KB Output is correct
52 Correct 209 ms 24108 KB Output is correct
53 Correct 78 ms 14180 KB Output is correct
54 Correct 79 ms 10196 KB Output is correct
55 Correct 197 ms 24152 KB Output is correct
56 Correct 188 ms 24152 KB Output is correct
57 Correct 76 ms 14292 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 4 ms 768 KB Output is correct
61 Correct 73 ms 10200 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 1 ms 400 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 67 ms 6368 KB Output is correct
66 Correct 69 ms 10196 KB Output is correct
67 Correct 76 ms 10212 KB Output is correct
68 Correct 73 ms 10204 KB Output is correct
69 Correct 75 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 176 ms 22180 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 175 ms 22120 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 684 KB Output is correct
17 Correct 76 ms 8268 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 42 ms 5864 KB Output is correct
21 Correct 182 ms 22128 KB Output is correct
22 Correct 168 ms 22092 KB Output is correct
23 Correct 189 ms 22124 KB Output is correct
24 Correct 168 ms 22092 KB Output is correct
25 Correct 81 ms 8164 KB Output is correct
26 Correct 76 ms 8396 KB Output is correct
27 Correct 171 ms 22156 KB Output is correct
28 Correct 190 ms 22156 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 1264 KB Output is correct
37 Correct 176 ms 22220 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 9 ms 1236 KB Output is correct
41 Correct 189 ms 22212 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 4 ms 596 KB Output is correct
45 Correct 83 ms 8176 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 400 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6352 KB Output is correct
50 Correct 213 ms 24176 KB Output is correct
51 Correct 185 ms 24152 KB Output is correct
52 Correct 209 ms 24108 KB Output is correct
53 Correct 78 ms 14180 KB Output is correct
54 Correct 79 ms 10196 KB Output is correct
55 Correct 197 ms 24152 KB Output is correct
56 Correct 188 ms 24152 KB Output is correct
57 Correct 76 ms 14292 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 43 ms 5836 KB Output is correct
62 Correct 196 ms 22116 KB Output is correct
63 Correct 174 ms 22092 KB Output is correct
64 Correct 195 ms 22092 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 46 ms 5964 KB Output is correct
67 Correct 176 ms 22176 KB Output is correct
68 Correct 171 ms 22084 KB Output is correct
69 Correct 196 ms 22128 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 49 ms 5864 KB Output is correct
74 Correct 178 ms 22140 KB Output is correct
75 Correct 177 ms 22128 KB Output is correct
76 Correct 182 ms 22108 KB Output is correct
77 Correct 183 ms 22132 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 4 ms 768 KB Output is correct
81 Correct 73 ms 10200 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 1 ms 400 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 67 ms 6368 KB Output is correct
86 Correct 69 ms 10196 KB Output is correct
87 Correct 76 ms 10212 KB Output is correct
88 Correct 73 ms 10204 KB Output is correct
89 Correct 75 ms 14160 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 3 ms 724 KB Output is correct
93 Correct 79 ms 10316 KB Output is correct
94 Correct 1 ms 396 KB Output is correct
95 Correct 1 ms 396 KB Output is correct
96 Correct 1 ms 400 KB Output is correct
97 Correct 19 ms 2760 KB Output is correct
98 Correct 74 ms 10208 KB Output is correct
99 Correct 73 ms 10204 KB Output is correct
100 Correct 71 ms 10200 KB Output is correct
101 Correct 74 ms 10188 KB Output is correct
102 Correct 73 ms 10196 KB Output is correct
103 Correct 71 ms 10212 KB Output is correct
104 Correct 72 ms 10188 KB Output is correct
105 Correct 82 ms 10212 KB Output is correct