Submission #810987

# Submission time Handle Problem Language Result Execution time Memory
810987 2023-08-06T19:02:08 Z oscar1f Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
211 ms 26516 KB
#include "supertrees.h"
#include<bits/stdc++.h>

using namespace std;
using vv=vector<vector<int>>;

const int MAX_SOM=1005;
int nbSom;
vv adja,rep;
int pere[MAX_SOM][2];
vector<int> listeFils[MAX_SOM],listeBoucle[MAX_SOM];

int find(int pos,int tab) {
	if (pere[pos][tab]!=pos) {
		pere[pos][tab]=find(pere[pos][tab],tab);
	}
	return pere[pos][tab];
}

int construct(vv p) {
	adja=p;
	nbSom=adja.size();
	for (int i=0;i<nbSom;i++) {
		rep.push_back({});
		for (int j=0;j<nbSom;j++) {
			rep.back().push_back(0);
		}
		pere[i][0]=i;
		pere[i][1]=i;
	}
	for (int i=0;i<nbSom;i++) {
		for (int j=i+1;j<nbSom;j++) {
			if (adja[i][j]==3) {
				return 0;
			}
			if (adja[i][j]==1) { 
				if (find(i,0)!=find(j,0)) {
					pere[find(i,0)][0]=find(j,0);
				}
			}
		}
	}	
	for (int i=0;i<nbSom;i++) {
		//cout<<i<<" : "<<find(i,0)<<endl;
		listeFils[find(i,0)].push_back(i);
	}
    for (int i=0;i<nbSom;i++) {
        for (int j=1;j<(int)listeFils[i].size();j++) {
            for (int k=0;k<nbSom;k++) {
                if (adja[listeFils[i][j]]!=adja[listeFils[i][j-1]]) {
                    return 0;
                }
            }
            rep[listeFils[i][j]][listeFils[i][j-1]]=1;
            rep[listeFils[i][j-1]][listeFils[i][j]]=1;
        }
    }
    for (int i=0;i<nbSom;i++) {
        for (int j=i+1;j<nbSom;j++) {
            if (!listeFils[i].empty() and !listeFils[j].empty() and adja[i][j]==2 and find(i,1)!=find(j,1)) {
                pere[find(i,1)][1]=find(j,1);
            }
        }
    }
    for (int i=0;i<nbSom;i++) {
        if (!listeFils[i].empty()) {
            listeBoucle[find(i,1)].push_back(i);
        }
    }
    for (int i=0;i<nbSom;i++) {
        if (listeBoucle[i].size()>1) {
            for (int j=0;j<(int)listeBoucle[i].size();j++) {
                rep[listeBoucle[i][j]][listeBoucle[i][(j+1)%listeBoucle[i].size()]]=1;
                rep[listeBoucle[i][(j+1)%listeBoucle[i].size()]][listeBoucle[i][j]]=1;
            }
        }
    }
    for (int i=0;i<nbSom;i++) {
        if (!listeFils[i].empty()) {
            for (int j=0;j<nbSom;j++) {
                if (i!=j) {
                    if (find(i,1)!=find(find(j,0),1)) {
                        if (adja[i][j]!=0) {
                            return 0;
                        } 
                    }
                    else if (find(i,0)!=find(j,0)) {
                        if (adja[i][j]!=2) {
                            return 0;
                        } 
                    }
                }
            }
        }
    }
	build(rep);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 205 ms 26300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 205 ms 26300 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 7 ms 1536 KB Output is correct
13 Correct 162 ms 26280 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 71 ms 16316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 45 ms 7028 KB Output is correct
21 Correct 199 ms 26240 KB Output is correct
22 Correct 186 ms 26256 KB Output is correct
23 Correct 207 ms 26276 KB Output is correct
24 Correct 167 ms 26232 KB Output is correct
25 Correct 101 ms 16320 KB Output is correct
26 Correct 81 ms 16272 KB Output is correct
27 Correct 207 ms 26300 KB Output is correct
28 Correct 169 ms 26408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 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 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 44 ms 6980 KB Output is correct
5 Correct 205 ms 26364 KB Output is correct
6 Correct 186 ms 26368 KB Output is correct
7 Correct 211 ms 26444 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 44 ms 7008 KB Output is correct
10 Correct 166 ms 26444 KB Output is correct
11 Correct 164 ms 26516 KB Output is correct
12 Correct 176 ms 26444 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 43 ms 6996 KB Output is correct
17 Correct 165 ms 26352 KB Output is correct
18 Correct 183 ms 26316 KB Output is correct
19 Correct 181 ms 26400 KB Output is correct
20 Correct 163 ms 26448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 205 ms 26300 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 7 ms 1536 KB Output is correct
13 Correct 162 ms 26280 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 71 ms 16316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 45 ms 7028 KB Output is correct
21 Correct 199 ms 26240 KB Output is correct
22 Correct 186 ms 26256 KB Output is correct
23 Correct 207 ms 26276 KB Output is correct
24 Correct 167 ms 26232 KB Output is correct
25 Correct 101 ms 16320 KB Output is correct
26 Correct 81 ms 16272 KB Output is correct
27 Correct 207 ms 26300 KB Output is correct
28 Correct 169 ms 26408 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Incorrect 0 ms 340 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 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 205 ms 26300 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 7 ms 1536 KB Output is correct
13 Correct 162 ms 26280 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1108 KB Output is correct
17 Correct 71 ms 16316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 45 ms 7028 KB Output is correct
21 Correct 199 ms 26240 KB Output is correct
22 Correct 186 ms 26256 KB Output is correct
23 Correct 207 ms 26276 KB Output is correct
24 Correct 167 ms 26232 KB Output is correct
25 Correct 101 ms 16320 KB Output is correct
26 Correct 81 ms 16272 KB Output is correct
27 Correct 207 ms 26300 KB Output is correct
28 Correct 169 ms 26408 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -