Submission #519874

# Submission time Handle Problem Language Result Execution time Memory
519874 2022-01-27T13:28:05 Z A_D Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
243 ms 28220 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;
const int N=1e3+110;
vector<int> g1[N];
vector<int> g2[N];
int vis[N];
int vis2[N];
vector<vector<int>> answer;
vector<int> vec;
vector<int> g[N];

void dfs(int u)
{
    vis[u]=1;
    for(auto x:g[u]){
        if(vis[x]){
            continue;
        }
        vec[x]++;
        vis[x]=1;
        dfs(x);
        vis[x]=0;
    }
}

int construct(vector<vector<int>> p){
	int n = p.size();
	vector<int> tmp(n);
	for(int i=0;i<n;i++){
        answer.push_back(tmp);
	}

	for(int i=0;i<n;i++){
        g1[i].push_back(i);
        g2[i].push_back(i);
        for(int j=i;j<n;j++){
            int v=p[i][j];
            if(v==3||(i==j&&v!=1)||p[i][j]!=p[j][i]){
                return 0;
            }
            if(v==2){
                g2[i].push_back(j);
                g2[j].push_back(i);

            }
            if(v==1&&i!=j){
                g1[i].push_back(j);
                g1[j].push_back(i);
            }
        }
	}
	for(int i=0;i<n;i++){
        sort(g1[i].begin(),g1[i].end());
        sort(g2[i].begin(),g2[i].end());
	}
	int cnt=0;
	for(int i=0;i<n;i++){
        if(vis[i]==0){
            cnt++;
            int sz=g1[i].size();
            vis[g1[i][0]]=cnt;
            for(int j=0;j<sz-1;j++){
                vis[g1[i][j]]=cnt;
                vis[g1[i][j+1]]=cnt;
                answer[g1[i][j]][g1[i][j+1]]=1;
                answer[g1[i][j+1]][g1[i][j]]=1;
                if(g1[g1[i][j]]!=g1[g1[i][j+1]])return 0;
            }
        }
	}
	for(int i=0;i<n;i++){
        if(vis2[vis[i]]==0){
            vis2[vis[g2[i][0]]]=1;
            int sz=g2[i].size();
            int lst=g2[i][0];
            for(int j=0;j<sz-1;j++){

            }
            for(int j=1;j<sz;j++){
                if(vis2[vis[g2[i][j]]]==0){
                    vis2[vis[g2[i][j]]]=1;
                    answer[lst][g2[i][j]]=1;
                    answer[g2[i][j]][lst]=1;
                 //   if(g2[g2[i][j]]!=g2[lst])return 0;
                    lst=g2[i][j];
                }
            }
            answer[lst][g2[i][0]]=1;
            answer[g2[i][0]][lst]=1;
        }
	}
    for(int i=0;i<n;i++){
        answer[i][i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(answer[i][j]){
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }
    for(int i=0;i<n;i++){
        memset(vis,0,sizeof(vis));
        vec.clear();
        vec.resize(n);
        dfs(i);
        vec[i]=1;
//        for(auto x:vec)cout<<x<<" ";cout<<endl;
        if(vec!=p[i])return 0;
    }
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1576 KB Output is correct
7 Correct 189 ms 28220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1576 KB Output is correct
7 Correct 189 ms 28220 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 13 ms 1228 KB Output is correct
13 Correct 168 ms 24136 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 4 ms 1008 KB Output is correct
17 Correct 89 ms 17092 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 372 KB Output is correct
20 Correct 42 ms 6376 KB Output is correct
21 Correct 243 ms 24676 KB Output is correct
22 Correct 196 ms 24112 KB Output is correct
23 Correct 185 ms 26144 KB Output is correct
24 Correct 182 ms 24128 KB Output is correct
25 Correct 80 ms 14704 KB Output is correct
26 Correct 85 ms 14188 KB Output is correct
27 Correct 190 ms 27208 KB Output is correct
28 Correct 186 ms 24136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 372 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 372 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 11 ms 1244 KB Output is correct
9 Correct 207 ms 24172 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 9 ms 1484 KB Output is correct
13 Correct 223 ms 28216 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 972 KB Output is correct
17 Correct 96 ms 17092 KB Output is correct
18 Correct 1 ms 372 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 70 ms 6368 KB Output is correct
22 Correct 172 ms 24632 KB Output is correct
23 Correct 230 ms 24208 KB Output is correct
24 Correct 189 ms 27200 KB Output is correct
25 Correct 81 ms 14148 KB Output is correct
26 Correct 73 ms 14664 KB Output is correct
27 Correct 205 ms 24260 KB Output is correct
28 Correct 185 ms 26172 KB Output is correct
29 Correct 90 ms 14148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 43 ms 6396 KB Output is correct
5 Correct 181 ms 24652 KB Output is correct
6 Correct 162 ms 24256 KB Output is correct
7 Correct 182 ms 26100 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 41 ms 6336 KB Output is correct
10 Correct 172 ms 24684 KB Output is correct
11 Correct 174 ms 24104 KB Output is correct
12 Correct 186 ms 27148 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 44 ms 6368 KB Output is correct
17 Correct 170 ms 24692 KB Output is correct
18 Correct 178 ms 24692 KB Output is correct
19 Correct 159 ms 24256 KB Output is correct
20 Correct 188 ms 24092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1576 KB Output is correct
7 Correct 189 ms 28220 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 13 ms 1228 KB Output is correct
13 Correct 168 ms 24136 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 4 ms 1008 KB Output is correct
17 Correct 89 ms 17092 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 372 KB Output is correct
20 Correct 42 ms 6376 KB Output is correct
21 Correct 243 ms 24676 KB Output is correct
22 Correct 196 ms 24112 KB Output is correct
23 Correct 185 ms 26144 KB Output is correct
24 Correct 182 ms 24128 KB Output is correct
25 Correct 80 ms 14704 KB Output is correct
26 Correct 85 ms 14188 KB Output is correct
27 Correct 190 ms 27208 KB Output is correct
28 Correct 186 ms 24136 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 372 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 372 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 1244 KB Output is correct
37 Correct 207 ms 24172 KB Output is correct
38 Correct 1 ms 376 KB Output is correct
39 Correct 1 ms 376 KB Output is correct
40 Correct 9 ms 1484 KB Output is correct
41 Correct 223 ms 28216 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 972 KB Output is correct
45 Correct 96 ms 17092 KB Output is correct
46 Correct 1 ms 372 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 70 ms 6368 KB Output is correct
50 Correct 172 ms 24632 KB Output is correct
51 Correct 230 ms 24208 KB Output is correct
52 Correct 189 ms 27200 KB Output is correct
53 Correct 81 ms 14148 KB Output is correct
54 Correct 73 ms 14664 KB Output is correct
55 Correct 205 ms 24260 KB Output is correct
56 Correct 185 ms 26172 KB Output is correct
57 Correct 90 ms 14148 KB Output is correct
58 Correct 0 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 4 ms 1124 KB Output is correct
61 Correct 90 ms 18752 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 372 KB Output is correct
65 Correct 46 ms 6352 KB Output is correct
66 Correct 74 ms 14784 KB Output is correct
67 Correct 71 ms 14788 KB Output is correct
68 Correct 71 ms 14400 KB Output is correct
69 Correct 81 ms 14144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 372 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 9 ms 1576 KB Output is correct
7 Correct 189 ms 28220 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 13 ms 1228 KB Output is correct
13 Correct 168 ms 24136 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 4 ms 1008 KB Output is correct
17 Correct 89 ms 17092 KB Output is correct
18 Correct 1 ms 376 KB Output is correct
19 Correct 1 ms 372 KB Output is correct
20 Correct 42 ms 6376 KB Output is correct
21 Correct 243 ms 24676 KB Output is correct
22 Correct 196 ms 24112 KB Output is correct
23 Correct 185 ms 26144 KB Output is correct
24 Correct 182 ms 24128 KB Output is correct
25 Correct 80 ms 14704 KB Output is correct
26 Correct 85 ms 14188 KB Output is correct
27 Correct 190 ms 27208 KB Output is correct
28 Correct 186 ms 24136 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 372 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 372 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 1244 KB Output is correct
37 Correct 207 ms 24172 KB Output is correct
38 Correct 1 ms 376 KB Output is correct
39 Correct 1 ms 376 KB Output is correct
40 Correct 9 ms 1484 KB Output is correct
41 Correct 223 ms 28216 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 5 ms 972 KB Output is correct
45 Correct 96 ms 17092 KB Output is correct
46 Correct 1 ms 372 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 70 ms 6368 KB Output is correct
50 Correct 172 ms 24632 KB Output is correct
51 Correct 230 ms 24208 KB Output is correct
52 Correct 189 ms 27200 KB Output is correct
53 Correct 81 ms 14148 KB Output is correct
54 Correct 73 ms 14664 KB Output is correct
55 Correct 205 ms 24260 KB Output is correct
56 Correct 185 ms 26172 KB Output is correct
57 Correct 90 ms 14148 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 0 ms 332 KB Output is correct
61 Correct 43 ms 6396 KB Output is correct
62 Correct 181 ms 24652 KB Output is correct
63 Correct 162 ms 24256 KB Output is correct
64 Correct 182 ms 26100 KB Output is correct
65 Correct 0 ms 332 KB Output is correct
66 Correct 41 ms 6336 KB Output is correct
67 Correct 172 ms 24684 KB Output is correct
68 Correct 174 ms 24104 KB Output is correct
69 Correct 186 ms 27148 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 0 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 44 ms 6368 KB Output is correct
74 Correct 170 ms 24692 KB Output is correct
75 Correct 178 ms 24692 KB Output is correct
76 Correct 159 ms 24256 KB Output is correct
77 Correct 188 ms 24092 KB Output is correct
78 Correct 0 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 4 ms 1124 KB Output is correct
81 Correct 90 ms 18752 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 372 KB Output is correct
85 Correct 46 ms 6352 KB Output is correct
86 Correct 74 ms 14784 KB Output is correct
87 Correct 71 ms 14788 KB Output is correct
88 Correct 71 ms 14400 KB Output is correct
89 Correct 81 ms 14144 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 0 ms 332 KB Output is correct
92 Correct 3 ms 844 KB Output is correct
93 Correct 72 ms 14144 KB Output is correct
94 Correct 0 ms 332 KB Output is correct
95 Correct 0 ms 372 KB Output is correct
96 Correct 0 ms 376 KB Output is correct
97 Correct 17 ms 3780 KB Output is correct
98 Correct 69 ms 14264 KB Output is correct
99 Correct 78 ms 14272 KB Output is correct
100 Correct 94 ms 14116 KB Output is correct
101 Correct 64 ms 14204 KB Output is correct
102 Correct 70 ms 14196 KB Output is correct
103 Correct 74 ms 14144 KB Output is correct
104 Correct 62 ms 14140 KB Output is correct
105 Correct 78 ms 14144 KB Output is correct