Submission #867850

# Submission time Handle Problem Language Result Execution time Memory
867850 2023-10-29T15:34:25 Z Ninedesu Connecting Supertrees (IOI20_supertrees) C++14
21 / 100
164 ms 22352 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;

const int N=1001;
int pa[N];
bool vis1[N];

int dsu(int x){
	if(pa[x]==x)return x;
	else return pa[x]=dsu(pa[x]);
}

int construct(vector<vector<int>> p) {
	int n=p.size();
	vector<vector<int>> ans;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		ans.push_back(row);
		pa[i]=i;
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(p[i][j]==3)return 0;
			if(p[i][j]==1)pa[dsu(j)]=dsu(i);
		}
	}
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i!=j&&dsu(i)==dsu(j)&&!vis1[i]){
                if(p[i][j]!=1)return 0;
                ans[i][j]=ans[j][i]=1;
                vis1[i]=vis1[j]=true;
            }
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(p[i][j]==2&&dsu(i)!=dsu(j)){
                ans[i][j]=ans[j][i]=1;
                pa[dsu(i)]=dsu(j);
                break;
            }
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(dsu(i)==dsu(j)&&!p[i][j])return 0;
        }
    }

	build(ans);
	return 1;
}

/*
6
1 2 2 0 0 0
2 1 2 0 0 0
2 2 1 0 0 0
0 0 0 1 2 2
0 0 0 2 1 2
0 0 0 2 2 1

12
1 2 2 2 2 1 1 1 1 2 2 2
2 1 2 2 2 2 2 2 2 1 1 2
2 2 1 2 2 2 2 2 2 2 2 2
2 2 2 1 2 2 2 2 2 2 2 2
2 2 2 2 1 2 2 2 2 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
1 2 2 2 2 1 1 1 1 2 2 2
2 1 2 2 2 2 2 2 2 1 1 2
2 1 2 2 2 2 2 2 2 1 1 2
2 2 2 2 2 2 2 2 2 2 2 1
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 154 ms 22024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 154 ms 22024 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 151 ms 22100 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 90 ms 12056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 47 ms 5680 KB Output is correct
21 Correct 164 ms 22088 KB Output is correct
22 Correct 153 ms 22044 KB Output is correct
23 Correct 159 ms 22024 KB Output is correct
24 Correct 155 ms 22352 KB Output is correct
25 Correct 61 ms 12060 KB Output is correct
26 Correct 63 ms 12116 KB Output is correct
27 Correct 159 ms 22168 KB Output is correct
28 Correct 151 ms 22096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Too few ways to get from 0 to 1, should be 2 found 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 154 ms 22024 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 151 ms 22100 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 90 ms 12056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 47 ms 5680 KB Output is correct
21 Correct 164 ms 22088 KB Output is correct
22 Correct 153 ms 22044 KB Output is correct
23 Correct 159 ms 22024 KB Output is correct
24 Correct 155 ms 22352 KB Output is correct
25 Correct 61 ms 12060 KB Output is correct
26 Correct 63 ms 12116 KB Output is correct
27 Correct 159 ms 22168 KB Output is correct
28 Correct 151 ms 22096 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 154 ms 22024 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 151 ms 22100 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 90 ms 12056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 47 ms 5680 KB Output is correct
21 Correct 164 ms 22088 KB Output is correct
22 Correct 153 ms 22044 KB Output is correct
23 Correct 159 ms 22024 KB Output is correct
24 Correct 155 ms 22352 KB Output is correct
25 Correct 61 ms 12060 KB Output is correct
26 Correct 63 ms 12116 KB Output is correct
27 Correct 159 ms 22168 KB Output is correct
28 Correct 151 ms 22096 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -