# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
469820 | AdamGS | Connecting Supertrees (IOI20_supertrees) | C++14 | 316 ms | 26020 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int construct(vector<vector<int>>p) {
int n=p[0].size();
rep(i, n) rep(j, n) if(p[i][j]==3) return 0;
vector<pair<vector<int>,int>>V;
rep(i, n) {
vector<int>a;
rep(j, n) if(p[i][j]) a.pb(1); else a.pb(0);
V.pb({a, i});
}
sort(all(V));
vector<vector<int>>spojne;
vector<int>akt1=V[0].st, akt2;
akt2.pb(V[0].nd);
for(int i=1; i<V.size(); ++i) {
if(V[i].st!=akt1) {
vector<int>jakie;
rep(j, n) if(akt1[j]) jakie.pb(j);
if(jakie!=akt2) return 0;
spojne.pb(akt2);
akt1=V[i].st;
akt2.clear();
}
akt2.pb(V[i].nd);
}
vector<int>jakie;
rep(j, n) if(akt1[j]) jakie.pb(j);
if(jakie!=akt2) return 0;
spojne.pb(akt2);
vector<vector<int>>ans;
rep(i, n) {
vector<int>a;
rep(j, n) a.pb(0);
ans.pb(a);
}
for(auto i : spojne) {
V.clear();
akt1.clear();
akt2.clear();
for(auto j : i) {
vector<int>a;
rep(l, n) a.pb(p[j][l]);
V.pb({a, j});
}
sort(all(V));
vector<vector<int>>drzewa;
akt1=V[0].st;
akt2.pb(V[0].nd);
for(int j=1; j<V.size(); ++j) {
if(V[j].st!=akt1) {
jakie.clear();
rep(l, n) if(akt1[l]==1) jakie.pb(l);
if(jakie!=akt2) return 0;
drzewa.pb(akt2);
akt1=V[j].st;
akt2.clear();
}
akt2.pb(V[j].nd);
}
jakie.clear();
rep(j, n) if(akt1[j]==1) jakie.pb(j);
if(jakie!=akt2) return 0;
drzewa.pb(akt2);
for(auto j : drzewa) {
int ile=0;
rep(l, n) if(p[j[0]][l]==1) ++ile;
if(ile!=j.size()) return 0;
rep(l, j.size()-1) {
ans[j[l]][j[l+1]]=ans[j[l+1]][j[l]]=1;
}
}
if(drzewa.size()==2) return 0;
if(drzewa.size()!=1) rep(j, drzewa.size()) {
ans[drzewa[j][0]][drzewa[(j+1)%drzewa.size()][0]]=1;
ans[drzewa[(j+1)%drzewa.size()][0]][drzewa[j][0]]=1;
}
}
build(ans);
return 1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |