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 "art.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
struct dsu{
vector<ll> e;
void init(int n){
e.resize(n+1,-1);
}
int get(int x){
if(e[x]<0){
return x;
}
else{
return e[x]=get(e[x]);
}
}
int size(int x){
return -e[get(x)];
}
bool same_set(int x,int y){
return (get(x)==get(y));
}
bool unite(int x,int y){
x=get(x);
y=get(y);
if(x==y){
return false;
}
if(e[x]>e[y]){
swap(x,y);
}
e[x]+=e[y];
e[y]=x;
return true;
}
};
vector<vector<ll>> g;
vector<ll> used;
vector<ll> indegree;
void dfs(ll v){
used[v]=1;
for(auto x:g[v]){
if(used[x]==0){
dfs(x);
}
}
}
void solve(int N){
g.resize(N+1);
indegree.resize(N+1,0);
vector<int> a;
for(int i=1;i<=N;i++){
for(int j=i+1;j<=N;j++){
used.clear();
used.resize(N+1,0);
dfs(i);
if(used[j]){
continue;
}
used.clear();
used.resize(N+1,0);
dfs(j);
if(used[i]){
continue;
}
a.pb(i);
a.pb(j);
for(int z=1;z<=N;z++){
if(z!=i && z!=j){
a.pb(z);
}
}
ll res1=publish(a);
swap(a[0],a[1]);
ll res2=publish(a);
if(res1<res2){
g[j].pb(i);
indegree[i]++;
}
else{
g[i].pb(j);
indegree[j]++;
}
a.clear();
}
}
queue<ll> q;
for(int i=1;i<=N;i++){
if(indegree[i]==0){
q.push(i);
}
}
while(!q.empty()){
ll v=q.front();
a.pb(v);
q.pop();
for(auto x:g[v]){
indegree[x]--;
if(indegree[x]==0){
q.push(x);
}
}
}
reverse(a.begin(),a.end());
answer(a);
}
Compilation message (stderr)
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | if(v.size() != N) {
| ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if(v.size() != N) {
| ~~~~~~~~~^~~~
# | 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... |