Submission #759295

# Submission time Handle Problem Language Result Execution time Memory
759295 2023-06-16T04:26:47 Z Piokemon Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
186 ms 24072 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

bool odw[1009];
int nr[1009];
vector<int> lista[1009];
int incykl[1009];

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<int> czesc(n,0);
	vector<vector<int>> answer(n,czesc);
	for(int i=0;i<=n;i++) odw[i]=0;
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (p[i][j]==3) return 0;
		}
	}
	for (int i=0;i<n;i++){
		if (odw[i]) continue;
		nr[i] = i;
		lista[i].push_back(i);
		odw[i] = 1;
		for (int j=0;j<n;j++){
			if (odw[j] || i==j) continue;
			if (p[i][j]==1){
				answer[i][j] = 1;
				answer[j][i] = 1;
				nr[j] = i;
				lista[i].push_back(j);
				odw[j] = 1;
			}
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (p[i][j] != p[nr[i]][j]) return 0;
		}
	}
	for(int i=0;i<=n;i++) odw[i]=0;

	/*cout << "nr: ";
	for (int i=0;i<n;i++) cout << nr[i] << ' ';
	cout << '\n';*/
	for (int i=0;i<n;i++){
		if (nr[i]!=i || odw[i]) continue;
		vector<int> cykl;
		cykl.push_back(i);
		odw[i] = 1;
		for (int j=0;j<n;j++){
			if (p[i][j]==2 && !odw[nr[j]]){
				cykl.push_back(nr[j]);
				odw[nr[j]] = 1;
			}
		}
		
		for (int j=0;j<=n;j++) incykl[j] = 0;
		for (int j:cykl) incykl[j] = 1; 

		for (int j:cykl){
			for (int k=0;k<n;k++){
				if (nr[k]==j){
					if (p[k][j] != 1) return 0;
				}
				else if (incykl[nr[k]]){
					if (p[k][j] != 2) return 0;
				}
				else{
					if (p[k][j] != 0) return 0;
				}
			}
		}

		/*cout << "cykl: ";
		for (int j:cykl){
			cout << j << ' ';
		}
		cout << '\n';*/
		if (cykl.size()==1) continue;
		for (int j=0;j<cykl.size()-1;j++){
			answer[cykl[j]][cykl[j+1]] = 1;
			answer[cykl[j+1]][cykl[j]] = 1;
		}
		answer[cykl.back()][cykl[0]] = 1;
		answer[cykl[0]][cykl.back()] =1;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:82:17: 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<cykl.size()-1;j++){
      |                ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1260 KB Output is correct
7 Correct 149 ms 23996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1260 KB Output is correct
7 Correct 149 ms 23996 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1264 KB Output is correct
13 Correct 150 ms 24048 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 65 ms 14100 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 39 ms 6224 KB Output is correct
21 Correct 148 ms 23960 KB Output is correct
22 Correct 161 ms 23940 KB Output is correct
23 Correct 156 ms 23964 KB Output is correct
24 Correct 185 ms 24048 KB Output is correct
25 Correct 62 ms 14108 KB Output is correct
26 Correct 65 ms 14100 KB Output is correct
27 Correct 150 ms 23952 KB Output is correct
28 Correct 186 ms 23992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 39 ms 6248 KB Output is correct
5 Correct 147 ms 24012 KB Output is correct
6 Correct 180 ms 24004 KB Output is correct
7 Correct 152 ms 23956 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 38 ms 6188 KB Output is correct
10 Correct 152 ms 23968 KB Output is correct
11 Correct 161 ms 23964 KB Output is correct
12 Correct 157 ms 24072 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 39 ms 6248 KB Output is correct
17 Correct 150 ms 23956 KB Output is correct
18 Correct 157 ms 24016 KB Output is correct
19 Correct 183 ms 23960 KB Output is correct
20 Correct 158 ms 24036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1260 KB Output is correct
7 Correct 149 ms 23996 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1264 KB Output is correct
13 Correct 150 ms 24048 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 65 ms 14100 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 39 ms 6224 KB Output is correct
21 Correct 148 ms 23960 KB Output is correct
22 Correct 161 ms 23940 KB Output is correct
23 Correct 156 ms 23964 KB Output is correct
24 Correct 185 ms 24048 KB Output is correct
25 Correct 62 ms 14108 KB Output is correct
26 Correct 65 ms 14100 KB Output is correct
27 Correct 150 ms 23952 KB Output is correct
28 Correct 186 ms 23992 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 9 ms 1260 KB Output is correct
7 Correct 149 ms 23996 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1264 KB Output is correct
13 Correct 150 ms 24048 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 65 ms 14100 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 39 ms 6224 KB Output is correct
21 Correct 148 ms 23960 KB Output is correct
22 Correct 161 ms 23940 KB Output is correct
23 Correct 156 ms 23964 KB Output is correct
24 Correct 185 ms 24048 KB Output is correct
25 Correct 62 ms 14108 KB Output is correct
26 Correct 65 ms 14100 KB Output is correct
27 Correct 150 ms 23952 KB Output is correct
28 Correct 186 ms 23992 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -