Submission #300825

# Submission time Handle Problem Language Result Execution time Memory
300825 2020-09-17T14:06:13 Z Dilshod_Imomov Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
273 ms 22280 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
int nn, comp, used[N], cc[N], cmp[N], ok, first[N];
set < int > sz[N];

int construct(std::vector<std::vector<int>> p) {
	nn = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < nn; i++) {
		std::vector<int> row;
		row.resize(nn);
		answer.push_back(row);
	}
	int sub1 = 1, cnt0 = 0, cnt1 = 0, cnt2 = 0;
	for ( int i = 0; i < nn; i++ ) {
        for ( int j = 0; j < nn ;j++ ) {
            if ( p[i][j] == 2 ) {
                sub1 = 0;
                cnt2 = 1;
            }
            if ( p[i][j] == 1 ) {
                cnt1 = 1;
            }
            if ( p[i][j] == 0 ) {
                cnt0 = 1;
            }
        }
	}
	for ( int i = 0; i < nn; i++ ) {
        if ( !cc[i] ) {
            cc[i] = ++comp;
            first[comp] = i;
            sz[cc[i]].insert(i);
        }
        cmp[ cc[i] ] = i;
        for ( int j = 0; j < nn; j++ ) {
            if ( p[i][j] == (sub1?1:2) && i != j ) {
                if ( cc[j] && cc[j] != cc[i] ) {
                    return 0;
                }
                if(  cc[j] ) {
                    continue;
                }
                cc[j] = cc[i];
                sz[cc[i]].insert(j);
                answer[ cmp[ cc[i] ] ][j] = 1;
                answer[ j ][ cmp[ cc[i] ] ] = 1;
                cmp[ cc[i] ] = j;
            }
        }
	}
	if ( !sub1 ) {
        for ( int i = 1; i <= comp; i++ ) {
            if ( cmp[ i ] != first[i] ) {
                answer[cmp[i]][first[i]] = 1;
                answer[ first[i] ][cmp[i]] = 1;
            }
            if ( sz[i].size() == 2 ) {
                return 0;
            }
        }
	}
    if ( cnt0 && cnt1 && cnt2 ) {
        for ( int i = 0; i < nn; i++ ) {
            for ( int j = 0; j < nn; j++ ) {
                if ( i != j && p[i][j] == 1 ) {
                    answer[i][j] = 1;
                    answer[j][i] = 1;
                }
            }
        }
        build(answer);
        return 1;
    }
    for ( int i = 0; i < nn; i++ ) {
        for ( int j = 0; j < nn; j++ ) {
            if ( cc[i] == cc[j] ) {
                if ( !p[i][j] || !p[j][i] ) {
                    return 0;
                }
            }
        }
    }
	build(answer);
	return 1;
}
/*
7
1 2 2 0 0 0 0
2 1 2 0 0 0 0
2 2 1 0 0 0 0
0 0 0 1 2 2 2
0 0 0 2 1 2 2
0 0 0 2 2 1 2
0 0 0 2 2 2 1
4
1 2 2 0
2 1 2 0
2 2 1 1
0 0 1 1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 263 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 263 ms 22136 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 249 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 10 ms 896 KB Output is correct
17 Correct 117 ms 12280 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 5884 KB Output is correct
21 Correct 263 ms 22136 KB Output is correct
22 Correct 273 ms 22136 KB Output is correct
23 Correct 257 ms 22136 KB Output is correct
24 Correct 243 ms 22264 KB Output is correct
25 Correct 111 ms 12280 KB Output is correct
26 Correct 102 ms 12280 KB Output is correct
27 Correct 263 ms 22136 KB Output is correct
28 Correct 237 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 10 ms 1280 KB Output is correct
9 Correct 237 ms 22264 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1280 KB Output is correct
13 Correct 260 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Incorrect 13 ms 1280 KB Answer gives possible 1 while actual possible 0
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 64 ms 5880 KB Output is correct
5 Correct 250 ms 22264 KB Output is correct
6 Correct 249 ms 22136 KB Output is correct
7 Correct 254 ms 22280 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 60 ms 5856 KB Output is correct
10 Correct 247 ms 22136 KB Output is correct
11 Correct 243 ms 22264 KB Output is correct
12 Correct 254 ms 22136 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Incorrect 1 ms 384 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 263 ms 22136 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 249 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 10 ms 896 KB Output is correct
17 Correct 117 ms 12280 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 5884 KB Output is correct
21 Correct 263 ms 22136 KB Output is correct
22 Correct 273 ms 22136 KB Output is correct
23 Correct 257 ms 22136 KB Output is correct
24 Correct 243 ms 22264 KB Output is correct
25 Correct 111 ms 12280 KB Output is correct
26 Correct 102 ms 12280 KB Output is correct
27 Correct 263 ms 22136 KB Output is correct
28 Correct 237 ms 22136 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 237 ms 22264 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 260 ms 22136 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Incorrect 13 ms 1280 KB Answer gives possible 1 while actual possible 0
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 263 ms 22136 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1280 KB Output is correct
13 Correct 249 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 10 ms 896 KB Output is correct
17 Correct 117 ms 12280 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 5884 KB Output is correct
21 Correct 263 ms 22136 KB Output is correct
22 Correct 273 ms 22136 KB Output is correct
23 Correct 257 ms 22136 KB Output is correct
24 Correct 243 ms 22264 KB Output is correct
25 Correct 111 ms 12280 KB Output is correct
26 Correct 102 ms 12280 KB Output is correct
27 Correct 263 ms 22136 KB Output is correct
28 Correct 237 ms 22136 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 10 ms 1280 KB Output is correct
37 Correct 237 ms 22264 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1280 KB Output is correct
41 Correct 260 ms 22136 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Incorrect 13 ms 1280 KB Answer gives possible 1 while actual possible 0
45 Halted 0 ms 0 KB -