# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977436 | 2024-05-08T01:59:32 Z | Amaarsaa | Connecting Supertrees (IOI20_supertrees) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> //#include "supertrees.h" using namespace std; vector < int > adj[1002]; int used[1002]; vector < int > v; void Go(int x) { used[x] = 1; v.push_back(x); for ( int X : adj[x]) { if (!used[X]) { Go(X); } } } int construct(vector< vector< int> > a) { int n = a.size(), i, j; vector < vector < int > > ans; ans.resize(n); for ( i = 0; i < n; i++) { ans[i].resize(n); for ( j = 0; j < n; j ++) { if ( a[i][j] != 0 && i != j) adj[i].push_back(j); } } for ( i = 0; i < n; i ++) { if ( used[i] == 0) { v.clear(); Go(i); for ( j = 1; j < v.size(); j ++) ans[v[j]][v[j - 1]] = ans[v[j - 1]][v[j]] = 1; } } build(ans); return 1; }