이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "meetings.h"
using namespace std;
/*
void Bridge(int a,int b)
{
cout<<a<<" "<<b<<endl;
}
int Query(int a,int b,int c)
{
cout<<a<<" "<<b<<" "<<c<<endl;
int ret;
cin>>ret;
return ret;
}
*/
map< pair< pair<int,int>,int>,int> seen;
int ask(int a,int b,int c)
{
if(a==b)return a;
if(a==c)return a;
if(b==c)return b;
if(a>b)swap(a,b);
if(a>c)swap(a,c);
if(b>c)swap(b,c);
pair< pair<int,int>,int> state={{a,b},c};
if(seen.count(state))return seen[state];
int d=Query(a,b,c);
seen[state]=d;
return d;
}
const int nmax=2e3+42;
vector< pair<int,int> > output;
void add_path(int a,int b)
{
output.push_back({a,b});
}
int n;
mt19937 rng(42);
int a_now,b_now;
bool cmp(int u,int v)
{
return ask(a_now,u,v)==u;
}
void solve(vector<int> active)
{
if(active.size()<=1)return;
shuffle(active.begin(),active.end(),rng);
int a=active[rng()%active.size()],b=active[rng()%active.size()];
while(a==b)a=active[rng()%active.size()],b=active[rng()%active.size()];
//cout<<"a= "<<a<<" b= "<<b<<endl;
vector<int> on_path={},remain={};
for(auto k:active)
if(k!=a&&k!=b)
{
if(ask(a,k,b)==k)on_path.push_back(k);
else remain.push_back(k);
}
a_now=a;
b_now=b;
sort(on_path.begin(),on_path.end(),cmp);
//cout<<a<<" ";for(auto k:on_path)cout<<k<<" ";cout<<b<<endl;
on_path.insert(on_path.begin(),a);
on_path.push_back(b);
for(int i=1;i<on_path.size();i++)
add_path(on_path[i-1],on_path[i]);
map<int, vector<int> > would_be={};
for(auto k:remain)
would_be[ask(a,k,b)].push_back(k);
for(auto k:would_be)
{
int node=k.first;
vector<int> on_subtree=k.second;
if(on_subtree.size()==0)continue;
vector< vector<int> > subtrees={};
for(auto w:on_subtree)
{
bool taken=0;
for(int i=0;i<subtrees.size();i++)
if(ask(node,subtrees[i].back(),w)!=node)
{
subtrees[i].push_back(w);
taken=1;
break;
}
if(taken==0)
{
subtrees.push_back({w});
}
}
for(auto subtree:subtrees)
{
solve(subtree);
int sub_root=subtree[0];
for(int j=1;j<subtree.size();j++)
if(sub_root!=node)sub_root=ask(sub_root,node,subtree[j]);
add_path(sub_root,node);
}
}
}
void Solve(int n)
{
vector<int> active={};
for(int i=0;i<n;i++)
active.push_back(i);
solve(active);
for(auto k:output)
{
if(k.first>k.second)swap(k.first,k.second);
Bridge(k.first,k.second);
}
}
/*
int main()
{
Solve(5);
}
*/
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'void solve(std::vector<int>)':
meetings.cpp:89:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<on_path.size();i++)
~^~~~~~~~~~~~~~~
meetings.cpp:111:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<subtrees.size();i++)
~^~~~~~~~~~~~~~~~
meetings.cpp:130:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<subtree.size();j++)
~^~~~~~~~~~~~~~~
# | 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... |