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 "doll.h"
#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef long long ll;
template<class T> bool umin(T& a, const T b){ if(a > b) { a = b; return true; } return false; }
template<class T> bool umax(T& a, const T b){ if(a < b) { a = b; return true; } return false; }
void create_circuit(int m, vector<int> a) {
int n = a.size();
vector<int> c(m + 1), x_(m), y_(m);
vector<int> cnt(m + 1);
a.insert(a.begin(), 0);
a.push_back(0);
for(int i=0;i<=n;i++){
cnt[a[i]]++;
}
vector<vector<int>> out(m + 1);
for(int i=1;i<=n+1;i++){
int x = a[i - 1], y = a[i];
//~ out[x].push_back(y);
if(cnt[y] == 1){
out[x].push_back(y);
} else {
out[x].push_back(-y);
}
}
int last = m;
auto get = [&](){
x_.push_back(0);
y_.push_back(0);
return ++last;
};
function<int(vector<int>&, int)> dfs = [&](vector<int>& a, int v){
if((int)a.size() == 1){
return a[0];
}
vector<int> l, r;
for(int i=0;i<(int)a.size();i++){
if(i & 1) r.push_back(a[i]);
else l.push_back(a[i]);
}
if(v == 0){
v = get();
}
if((int)a.size() & 1){
r.push_back(l.back());
l.back() = -v;
}
//~ cout<<"before: "<<dfs(l, 0)<<" "<<dfs(r, 0)<<endl;
int tmpLeft = dfs(l, 0);
int tmpRight = dfs(r, 0);
x_[v - 1] = tmpLeft;
y_[v - 1] = tmpRight;
return -v;
};
//~ for(int i=0;i<=m;i++){
//~ cout<<cnt[i]<<" ";
//~ } cout<<endl;
for(int i=0;i<=m;i++){
if(!cnt[i]) continue;
if(cnt[i] == 1){
//~ cout<<i<<endl;
c[i] = out[i][0];
continue;
}
vector<int> a_(cnt[i], i);
//~ cout<<i<<" : ";
//~ for(auto x : a_) cout<<x<<" ";
//~ cout<<endl;
dfs(a_, i);
//~ x_[i - 1] = x_[root];
//~ y_[i - 1] = y_[root];
c[i] = dfs(out[i], 0);
}
//~ for(int i=0;i<=m;i++){
//~ cout<<i<<" : ";
//~ for(auto x : out[i]) cout<<x<<" ";
//~ cout<<endl;
//~ }
//~ for(int i=0;i<=m;i++){
//~ cout<<i<<" "<<c[i]<<"\n";
//~ cout<<c[i]<<" ";
//~ }
//~ cout<<endl;
//~ cout<<(int)x_.size()<<" "<<last<<endl;
//~ for(int i=0;i<last;i++){
//~ cout<<-(i + 1)<<" ";
//~ } cout<<endl;
//~ for(int i=0;i<last;i++){
//~ if(!x_[i]) continue;
//~ cout<<-(i + 1)<<" "<<x_[i]<<"\n";
//~ cout<<x_[i]<<" ";
//~ } cout<<endl;
//~ for(int i=0;i<last;i++){
//~ if(!y_[i]) continue;
//~ cout<<-(i + 1)<<" "<<y_[i]<<"\n";
//~ cout<<y_[i]<<" ";
//~ } cout<<endl;
answer(c, x_, y_);
}
# | 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... |