Submission #300944

#TimeUsernameProblemLanguageResultExecution timeMemory
300944Dilshod_ImomovConnecting Supertrees (IOI20_supertrees)C++17
40 / 100
366 ms22392 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 7; int nn, comp, used[N], cc[N], cmp[N], tp[N], 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, cnt1 = 0, cnt2 = 0; vector < pair < int, int > > vc; 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 && i != j ) { cnt1 = 1; tp[i] = 1; } } } for ( int i = 0; i < nn; i++ ) { if ( !sub1 && tp[i] ) { continue; } 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 && (!tp[j] || sub1) ) { if ( cc[j] && cc[j] != cc[i] ) { return 0; } if( cc[j] ) { continue; } cc[j] = cc[i]; sz[cc[i]].insert(j); //cout << cmp[ cc[i] ] << ' ' << j << endl; answer[ cmp[ cc[i] ] ][j] = 1; answer[ j ][ cmp[ cc[i] ] ] = 1; cmp[ cc[i] ] = j; } } } if ( !sub1 && !(cnt1 && cnt2) ) { 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 ( cnt1 && cnt2 ) { for ( int i = 0; i < nn; i++ ) { //cout << i << ' ' << cc[i] << ' ' << first[ cc[i] ] << endl; if ( tp[i] || first[ cc[i] ] != i ) { continue; } //cout << i << endl; int s = i; for ( int j = 0; j < nn; j++ ) { if ( i != j && tp[j] && !used[j] ) { s = j; break; } } if ( s == i ) { continue; } //cout << i << ' ' << s << endl; answer[i][s] = 1; answer[s][i] = 1; answer[cmp[cc[i]]][s] = 1; answer[s][cmp[cc[i]]] = 1; used[s] = 1; for ( int j = 0; j < nn; j++ ) { if ( s != j && tp[j] ) { answer[s][j] = 1; answer[j][s] = 1; used[j] = 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; } /* 8 1 2 2 0 0 0 0 0 2 1 2 0 0 0 0 0 2 2 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 2 2 0 0 0 0 0 2 1 2 0 0 0 0 0 2 2 1 5 1 2 2 2 2 2 1 2 2 2 2 2 1 1 1 2 2 1 1 1 2 2 1 1 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...