Submission #385706

# Submission time Handle Problem Language Result Execution time Memory
385706 2021-04-04T18:58:23 Z DavidDamian Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
268 ms 22380 KB
#include "supertrees.h"
#include <vector>
using namespace std;
int link[1005];
int setSize[1005];
void init(int n)
{
    for(int i=1;i<=n;i++){
        link[i]=i;
        setSize[i]=1;
    }
}
int root(int u)
{
    if(link[u]==u) return u;
    else return link[u]=root(link[u]);
}
bool same(int a,int b)
{
    return root(a)==root(b);
}
void unite(int a,int b)
{
    a=root(a);
    b=root(b);
    if(setSize[b]>setSize[a])
        swap(a,b);
    setSize[a]+=setSize[b];
    link[b]=a;
}
int construct(vector< vector<int> > p) {
	int n = p.size();
	init(n+3);
	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++){
        for(int j=0;j<n;j++){
            if(p[i][j]==1 && !same(i+1,j+1)){
                int a=root(i+1);
                int b=root(j+1);
                answer[a-1][b-1]=1;
                answer[b-1][a-1]=1;
                unite(a,b);
            }
        }
	}
	bool possible=true;
	for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(p[i][j]!=same(i+1,j+1))
                possible=false;
        }
	}
	if(!possible)
        return 0;
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 260 ms 22124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 260 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 246 ms 22380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 130 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 5868 KB Output is correct
21 Correct 260 ms 22104 KB Output is correct
22 Correct 250 ms 22232 KB Output is correct
23 Correct 268 ms 22252 KB Output is correct
24 Correct 241 ms 22124 KB Output is correct
25 Correct 119 ms 12140 KB Output is correct
26 Correct 118 ms 12140 KB Output is correct
27 Correct 263 ms 22252 KB Output is correct
28 Correct 243 ms 22124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 260 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 246 ms 22380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 130 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 5868 KB Output is correct
21 Correct 260 ms 22104 KB Output is correct
22 Correct 250 ms 22232 KB Output is correct
23 Correct 268 ms 22252 KB Output is correct
24 Correct 241 ms 22124 KB Output is correct
25 Correct 119 ms 12140 KB Output is correct
26 Correct 118 ms 12140 KB Output is correct
27 Correct 263 ms 22252 KB Output is correct
28 Correct 243 ms 22124 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 260 ms 22124 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 246 ms 22380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 748 KB Output is correct
17 Correct 130 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 5868 KB Output is correct
21 Correct 260 ms 22104 KB Output is correct
22 Correct 250 ms 22232 KB Output is correct
23 Correct 268 ms 22252 KB Output is correct
24 Correct 241 ms 22124 KB Output is correct
25 Correct 119 ms 12140 KB Output is correct
26 Correct 118 ms 12140 KB Output is correct
27 Correct 263 ms 22252 KB Output is correct
28 Correct 243 ms 22124 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -