Submission #400052

# Submission time Handle Problem Language Result Execution time Memory
400052 2021-05-07T09:17:05 Z pliam Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
254 ms 24064 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

vector<bool> visited;
vector<int> cindex,lindex;
vector<vector<int>> matrix;

int construct(vector<vector<int>> p){
    int N=p.size();
    cindex.resize(N);
    lindex.resize(N);
    visited.resize(N);
    matrix.resize(N);
    for(int i=0;i<N;i++){
        visited[i]=false;
        cindex[i]=i;
        lindex[i]=i;
        matrix[i].resize(N);
        for(int j=0;j<N;j++){
            if(p[i][j]==3) return 0;
        }
    }
    for(int i=0;i<N;i++){
        if(visited[i]) continue;
        visited[i]=true;
        int cycle_size=1;
        int last2=i;
        for(int j=0;j<N;j++){
            if(visited[j] || p[i][j]==0) continue;
            visited[j]=true;
            if(p[i][j]==1){
                matrix[i][j]=matrix[j][i]=1;
                lindex[j]=i;
            }
            if(p[i][j]==2){
                matrix[last2][j]=matrix[j][last2]=1;
                cycle_size++;
                last2=j;
                lindex[j]=j;
                for(int k=0;k<N;k++){
                    if(visited[k]) continue;
                    if(p[j][k]==1){
                        visited[k]=true;
                        lindex[k]=j;
                        cindex[k]=i;
                        matrix[j][k]=matrix[k][j]=1;
                    }
                }
            }
            cindex[j]=i;
        }
        if(cycle_size==2) return 0;
        if(cycle_size!=1) matrix[i][last2]=matrix[last2][i]=1;
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(lindex[i]==lindex[j]){ if(p[i][j]!=1) return 0;}
            else if(cindex[i]==cindex[j]) {if(p[i][j]!=2) return 0;}
            else if(p[i][j]!=0) return 0;
        }
    }
    build(matrix);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 239 ms 24004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 239 ms 24004 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 249 ms 23932 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 104 ms 14076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 63 ms 6212 KB Output is correct
21 Correct 243 ms 24004 KB Output is correct
22 Correct 250 ms 23944 KB Output is correct
23 Correct 252 ms 23928 KB Output is correct
24 Correct 248 ms 24008 KB Output is correct
25 Correct 105 ms 14076 KB Output is correct
26 Correct 104 ms 14020 KB Output is correct
27 Correct 246 ms 23928 KB Output is correct
28 Correct 246 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 11 ms 1228 KB Output is correct
9 Correct 251 ms 24008 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1212 KB Output is correct
13 Correct 237 ms 24004 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 820 KB Output is correct
17 Correct 106 ms 14020 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 62 ms 6244 KB Output is correct
22 Correct 252 ms 23936 KB Output is correct
23 Correct 250 ms 23920 KB Output is correct
24 Correct 249 ms 23928 KB Output is correct
25 Correct 105 ms 14068 KB Output is correct
26 Correct 104 ms 14020 KB Output is correct
27 Correct 247 ms 23928 KB Output is correct
28 Correct 250 ms 23988 KB Output is correct
29 Correct 107 ms 14152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 62 ms 6252 KB Output is correct
5 Correct 248 ms 23920 KB Output is correct
6 Correct 247 ms 24056 KB Output is correct
7 Correct 254 ms 24060 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 63 ms 6260 KB Output is correct
10 Correct 254 ms 23924 KB Output is correct
11 Correct 247 ms 24004 KB Output is correct
12 Correct 248 ms 23940 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 63 ms 6148 KB Output is correct
17 Correct 247 ms 23928 KB Output is correct
18 Correct 245 ms 23940 KB Output is correct
19 Correct 247 ms 24004 KB Output is correct
20 Correct 254 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 239 ms 24004 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 249 ms 23932 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 104 ms 14076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 63 ms 6212 KB Output is correct
21 Correct 243 ms 24004 KB Output is correct
22 Correct 250 ms 23944 KB Output is correct
23 Correct 252 ms 23928 KB Output is correct
24 Correct 248 ms 24008 KB Output is correct
25 Correct 105 ms 14076 KB Output is correct
26 Correct 104 ms 14020 KB Output is correct
27 Correct 246 ms 23928 KB Output is correct
28 Correct 246 ms 24064 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1228 KB Output is correct
37 Correct 251 ms 24008 KB Output is correct
38 Correct 1 ms 296 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1212 KB Output is correct
41 Correct 237 ms 24004 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 820 KB Output is correct
45 Correct 106 ms 14020 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 62 ms 6244 KB Output is correct
50 Correct 252 ms 23936 KB Output is correct
51 Correct 250 ms 23920 KB Output is correct
52 Correct 249 ms 23928 KB Output is correct
53 Correct 105 ms 14068 KB Output is correct
54 Correct 104 ms 14020 KB Output is correct
55 Correct 247 ms 23928 KB Output is correct
56 Correct 250 ms 23988 KB Output is correct
57 Correct 107 ms 14152 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 5 ms 844 KB Output is correct
61 Correct 104 ms 14004 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 64 ms 6256 KB Output is correct
66 Correct 106 ms 14072 KB Output is correct
67 Correct 103 ms 14020 KB Output is correct
68 Correct 103 ms 14080 KB Output is correct
69 Correct 100 ms 14076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 239 ms 24004 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 249 ms 23932 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 104 ms 14076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 63 ms 6212 KB Output is correct
21 Correct 243 ms 24004 KB Output is correct
22 Correct 250 ms 23944 KB Output is correct
23 Correct 252 ms 23928 KB Output is correct
24 Correct 248 ms 24008 KB Output is correct
25 Correct 105 ms 14076 KB Output is correct
26 Correct 104 ms 14020 KB Output is correct
27 Correct 246 ms 23928 KB Output is correct
28 Correct 246 ms 24064 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1228 KB Output is correct
37 Correct 251 ms 24008 KB Output is correct
38 Correct 1 ms 296 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1212 KB Output is correct
41 Correct 237 ms 24004 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 820 KB Output is correct
45 Correct 106 ms 14020 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 62 ms 6244 KB Output is correct
50 Correct 252 ms 23936 KB Output is correct
51 Correct 250 ms 23920 KB Output is correct
52 Correct 249 ms 23928 KB Output is correct
53 Correct 105 ms 14068 KB Output is correct
54 Correct 104 ms 14020 KB Output is correct
55 Correct 247 ms 23928 KB Output is correct
56 Correct 250 ms 23988 KB Output is correct
57 Correct 107 ms 14152 KB Output is correct
58 Correct 1 ms 300 KB Output is correct
59 Correct 1 ms 296 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 62 ms 6252 KB Output is correct
62 Correct 248 ms 23920 KB Output is correct
63 Correct 247 ms 24056 KB Output is correct
64 Correct 254 ms 24060 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 63 ms 6260 KB Output is correct
67 Correct 254 ms 23924 KB Output is correct
68 Correct 247 ms 24004 KB Output is correct
69 Correct 248 ms 23940 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 63 ms 6148 KB Output is correct
74 Correct 247 ms 23928 KB Output is correct
75 Correct 245 ms 23940 KB Output is correct
76 Correct 247 ms 24004 KB Output is correct
77 Correct 254 ms 23936 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 5 ms 844 KB Output is correct
81 Correct 104 ms 14004 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 64 ms 6256 KB Output is correct
86 Correct 106 ms 14072 KB Output is correct
87 Correct 103 ms 14020 KB Output is correct
88 Correct 103 ms 14080 KB Output is correct
89 Correct 100 ms 14076 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 588 KB Output is correct
93 Correct 95 ms 10104 KB Output is correct
94 Correct 1 ms 296 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 26 ms 2804 KB Output is correct
98 Correct 99 ms 10476 KB Output is correct
99 Correct 100 ms 10744 KB Output is correct
100 Correct 99 ms 10436 KB Output is correct
101 Correct 99 ms 11384 KB Output is correct
102 Correct 95 ms 10096 KB Output is correct
103 Correct 93 ms 10052 KB Output is correct
104 Correct 92 ms 10100 KB Output is correct
105 Correct 102 ms 10092 KB Output is correct