Submission #487888

# Submission time Handle Problem Language Result Execution time Memory
487888 2021-11-16T21:43:42 Z ala2 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
233 ms 26168 KB
#include "supertrees.h"
#include <vector>
#include<iostream>
using namespace std;
int pa[1001000];
int sz[1001000];
int root(int x)
{
    while(x!=pa[x])
    {
        pa[x]=pa[pa[x]];
        x=pa[x];
    }
    return x;
}

void unit(int x,int y)
{
    x=root(x);
    y=root(y);
    if(x==y)
        return ;
    if(sz[x]>sz[y])
    {
        sz[x]+=sz[y];
        pa[y]=x;
    }
    else
    {
        sz[y]+=sz[x];
        pa[x]=y;
    }
}

vector<int>v[1010];
int vi[1010];
int vis[5][1010][1010];
int construct(vector<vector<int>> p) {
	int n = p.size();
	int bb=0;
	vector<vector<int>> answer;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	for(int i=0;i<n;i++)
    {
        pa[i]=i;
        sz[i]=1;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(p[i][j]==1)
            {
                unit(i,j);
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        v[root(i)].push_back(i);
    }
    for(int i=0;i<n;i++)
    {
        if(i!=root(i))
            continue;
        if(v[i].size()==1)
        {
            continue;
        }
        for(int j=0;j<v[i].size()-1;j++)
        {
            int x=v[i][j];
            int y=v[i][j+1];
            answer[x][y]=1;
            answer[y][x]=1;
        }
    }

    for(int i=0;i<n;i++)
    {
        if(i!=root(i))
            continue;
        int tow=0; int three=0;
        vector<int>r;
        r.push_back(i);
        vi[root(i)]=1;
        for(int j=0;j<n;j++)
        {
            if(p[i][j]>=2&&!vi[root(j)])
            {
                if(p[i][j]==2)
                    tow=2;
                else tow=3,three=1;
                r.push_back(root(j));
                vi[root(j)]=1;
            }
        }
        if(tow&&three){
            bb=1;
            break;
        }
       // cout<<"           "<<r.size()<<endl;
       if(r.size()==1)
            continue;
        if(r.size()==2&&tow==2){
        bb=1;
        break;
        }
        if(r.size()<=3&&tow==3){
        bb=1;
        break;
        }

        for(int k=0;k<r.size()-1;k++)
        {
            int x=r[k];
            int y=r[k+1];
            answer[x][y]=1;
            answer[y][x]=1;
        }
        int ss=r.size()-1;
        answer[r[ss]][r[0]]=1;
        answer[r[0]][r[ss]]=1;
        if(tow>2){
        answer[r[0]][r[2]]=1;
        answer[r[2]][r[0]]=1;
        }
        for(int ii=0;ii<r.size();ii++)
        {
            for(int jj=0;jj<r.size();jj++)
            {
                if(ii==jj)
                    continue;
                vis[tow][r[ii]][r[jj]]=1;
                vis[tow][r[jj]][r[ii]]=1;
            }
        }

    }
    for(int i=0;i<n;i++)
    {
        answer[i][i]=0;
        for(int j=0;j<n;j++)
        {
            if(i==j)
                continue;
         //   cout<<vis[i][j]<<" ";
            if(p[i][j]==2&&vis[3][root(i)][root(j)])
                bb=1;
            if(p[i][j]==3&&vis[2][root(i)][root(j)])
                bb=1;
            if(p[i][j]>=2&&!vis[p[i][j]][root(i)][root(j)])
                bb=1;
            if(p[i][j]<2&&vis[p[i][j]][root(i)][root(j)])
                bb=1;
            if(p[i][j]==1&&root(i)!=root(j))
                bb=1;
            if(root(i)==root(j)&&p[i][j]!=1)
                bb=1;
            if(p[i][j]==0&&vis[3][root(i)][root(j)])
                bb=1;
                if(p[i][j]==0&&vis[2][root(i)][root(j)])
                bb=1;
        }

    }

    if(bb)
        return 0;
    else
    {
	build(answer);
	return 1;
    }

}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for(int j=0;j<v[i].size()-1;j++)
      |                     ~^~~~~~~~~~~~~~
supertrees.cpp:118:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |         for(int k=0;k<r.size()-1;k++)
      |                     ~^~~~~~~~~~~
supertrees.cpp:132:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |         for(int ii=0;ii<r.size();ii++)
      |                      ~~^~~~~~~~~
supertrees.cpp:134:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |             for(int jj=0;jj<r.size();jj++)
      |                          ~~^~~~~~~~~
supertrees.cpp:164:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  164 |             if(p[i][j]==0&&vis[3][root(i)][root(j)])
      |             ^~
supertrees.cpp:166:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  166 |                 if(p[i][j]==0&&vis[2][root(i)][root(j)])
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1228 KB Output is correct
7 Correct 172 ms 22032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1228 KB Output is correct
7 Correct 172 ms 22032 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 184 ms 22056 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 97 ms 12196 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 47 ms 5788 KB Output is correct
21 Correct 173 ms 22056 KB Output is correct
22 Correct 183 ms 22052 KB Output is correct
23 Correct 184 ms 22060 KB Output is correct
24 Correct 182 ms 22096 KB Output is correct
25 Correct 84 ms 12084 KB Output is correct
26 Correct 84 ms 12196 KB Output is correct
27 Correct 218 ms 22064 KB Output is correct
28 Correct 186 ms 22212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 8 ms 1256 KB Output is correct
9 Correct 170 ms 22100 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 9 ms 1996 KB Output is correct
13 Correct 181 ms 26032 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 5 ms 1740 KB Output is correct
17 Correct 119 ms 16184 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 45 ms 7620 KB Output is correct
22 Correct 180 ms 26144 KB Output is correct
23 Correct 199 ms 26020 KB Output is correct
24 Correct 194 ms 26056 KB Output is correct
25 Correct 94 ms 12580 KB Output is correct
26 Correct 86 ms 16208 KB Output is correct
27 Correct 173 ms 26028 KB Output is correct
28 Correct 223 ms 26064 KB Output is correct
29 Correct 78 ms 12580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 44 ms 5732 KB Output is correct
5 Correct 180 ms 22064 KB Output is correct
6 Correct 210 ms 22088 KB Output is correct
7 Correct 183 ms 22060 KB Output is correct
8 Correct 0 ms 252 KB Output is correct
9 Correct 50 ms 7664 KB Output is correct
10 Correct 181 ms 26020 KB Output is correct
11 Correct 176 ms 26168 KB Output is correct
12 Correct 233 ms 26108 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 54 ms 7504 KB Output is correct
17 Correct 192 ms 26020 KB Output is correct
18 Correct 178 ms 25156 KB Output is correct
19 Correct 177 ms 25392 KB Output is correct
20 Correct 170 ms 22316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1228 KB Output is correct
7 Correct 172 ms 22032 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 184 ms 22056 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 97 ms 12196 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 47 ms 5788 KB Output is correct
21 Correct 173 ms 22056 KB Output is correct
22 Correct 183 ms 22052 KB Output is correct
23 Correct 184 ms 22060 KB Output is correct
24 Correct 182 ms 22096 KB Output is correct
25 Correct 84 ms 12084 KB Output is correct
26 Correct 84 ms 12196 KB Output is correct
27 Correct 218 ms 22064 KB Output is correct
28 Correct 186 ms 22212 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 8 ms 1256 KB Output is correct
37 Correct 170 ms 22100 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 9 ms 1996 KB Output is correct
41 Correct 181 ms 26032 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 0 ms 332 KB Output is correct
44 Correct 5 ms 1740 KB Output is correct
45 Correct 119 ms 16184 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 45 ms 7620 KB Output is correct
50 Correct 180 ms 26144 KB Output is correct
51 Correct 199 ms 26020 KB Output is correct
52 Correct 194 ms 26056 KB Output is correct
53 Correct 94 ms 12580 KB Output is correct
54 Correct 86 ms 16208 KB Output is correct
55 Correct 173 ms 26028 KB Output is correct
56 Correct 223 ms 26064 KB Output is correct
57 Correct 78 ms 12580 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 7 ms 748 KB Output is correct
61 Correct 112 ms 12204 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
63 Correct 0 ms 332 KB Output is correct
64 Correct 0 ms 332 KB Output is correct
65 Correct 49 ms 7492 KB Output is correct
66 Correct 89 ms 16292 KB Output is correct
67 Correct 95 ms 15596 KB Output is correct
68 Correct 84 ms 15156 KB Output is correct
69 Correct 76 ms 12332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1228 KB Output is correct
7 Correct 172 ms 22032 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 184 ms 22056 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 97 ms 12196 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 47 ms 5788 KB Output is correct
21 Correct 173 ms 22056 KB Output is correct
22 Correct 183 ms 22052 KB Output is correct
23 Correct 184 ms 22060 KB Output is correct
24 Correct 182 ms 22096 KB Output is correct
25 Correct 84 ms 12084 KB Output is correct
26 Correct 84 ms 12196 KB Output is correct
27 Correct 218 ms 22064 KB Output is correct
28 Correct 186 ms 22212 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 0 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 8 ms 1256 KB Output is correct
37 Correct 170 ms 22100 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 9 ms 1996 KB Output is correct
41 Correct 181 ms 26032 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 0 ms 332 KB Output is correct
44 Correct 5 ms 1740 KB Output is correct
45 Correct 119 ms 16184 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 45 ms 7620 KB Output is correct
50 Correct 180 ms 26144 KB Output is correct
51 Correct 199 ms 26020 KB Output is correct
52 Correct 194 ms 26056 KB Output is correct
53 Correct 94 ms 12580 KB Output is correct
54 Correct 86 ms 16208 KB Output is correct
55 Correct 173 ms 26028 KB Output is correct
56 Correct 223 ms 26064 KB Output is correct
57 Correct 78 ms 12580 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 0 ms 332 KB Output is correct
61 Correct 44 ms 5732 KB Output is correct
62 Correct 180 ms 22064 KB Output is correct
63 Correct 210 ms 22088 KB Output is correct
64 Correct 183 ms 22060 KB Output is correct
65 Correct 0 ms 252 KB Output is correct
66 Correct 50 ms 7664 KB Output is correct
67 Correct 181 ms 26020 KB Output is correct
68 Correct 176 ms 26168 KB Output is correct
69 Correct 233 ms 26108 KB Output is correct
70 Correct 0 ms 332 KB Output is correct
71 Correct 0 ms 332 KB Output is correct
72 Correct 0 ms 332 KB Output is correct
73 Correct 54 ms 7504 KB Output is correct
74 Correct 192 ms 26020 KB Output is correct
75 Correct 178 ms 25156 KB Output is correct
76 Correct 177 ms 25392 KB Output is correct
77 Correct 170 ms 22316 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 0 ms 332 KB Output is correct
80 Correct 7 ms 748 KB Output is correct
81 Correct 112 ms 12204 KB Output is correct
82 Correct 0 ms 332 KB Output is correct
83 Correct 0 ms 332 KB Output is correct
84 Correct 0 ms 332 KB Output is correct
85 Correct 49 ms 7492 KB Output is correct
86 Correct 89 ms 16292 KB Output is correct
87 Correct 95 ms 15596 KB Output is correct
88 Correct 84 ms 15156 KB Output is correct
89 Correct 76 ms 12332 KB Output is correct
90 Correct 0 ms 332 KB Output is correct
91 Correct 0 ms 332 KB Output is correct
92 Correct 7 ms 852 KB Output is correct
93 Correct 133 ms 12196 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 0 ms 332 KB Output is correct
96 Correct 0 ms 332 KB Output is correct
97 Correct 21 ms 4144 KB Output is correct
98 Correct 84 ms 16160 KB Output is correct
99 Correct 86 ms 15140 KB Output is correct
100 Correct 85 ms 15136 KB Output is correct
101 Correct 83 ms 12400 KB Output is correct
102 Correct 78 ms 12196 KB Output is correct
103 Correct 87 ms 14116 KB Output is correct
104 Correct 86 ms 14112 KB Output is correct
105 Correct 94 ms 14152 KB Output is correct