이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#include "Azer.h"
vector<pair<int,int>> adj[2001];
int dist[2001];
int vis[2001];
int num=0;
int cur=0;
int st=0;
int last=0;
pair<int,int> best;
int num2=0;
int cur2=0;
int n;
int kk=0;
vector<int> Answer(){
vector<int> ans2;
for(int i=0;i<n;i++){
ans2.pb(dist[i]);
}
return ans2;
}
void ReceiveA(bool x){
if(st==0){
if(cur==0){
for(auto j:adj[last]){
if(dist[j.a]==-1 or dist[j.a]>dist[last]+j.b){
dist[j.a]=dist[last]+j.b;
}
}
best={-1,-1};
for(int i=0;i<n;i++){
// //////cout<<i<<":::"<<dist[i]<<endl;
if(vis[i]==0 and dist[i]!=-1){
if(best.a==-1){
best={dist[i],i};
}
else{
if(dist[i]<best.a){
best={dist[i],i};
}
}
}
}
if(best.a==-1){
best.a=(1<<9)-1;
}
//cout<<best.a<<","<<best.b<<endl;
}
if(x){
//cout<<cur<<endl;
num+=(1<<cur);
//////cout<<num<<endl;
////cout<<cur<<"<<"<<num<<",,"<<best.a<<endl;
/* if((best.a&(1<<(19-cur)))==0 and kk==0){
st=3;
//cout<<333<<endl;
SendA(1);
////cout<<444<<endl;
ReceiveA(0);
return;
// SendA(1);
} */
}
/* else{
if((best.a&(1<<(19-cur)))){
kk=1;
// ////cout<<1111<<endl;
}
}*/
cur+=1;
if(cur==9){
cur=0;
st=1;
}
else{
return;
}
//////cout<<cur<<"<"<<num<<endl;
}
if(st==1){
//////cout<<best.a<<"::"<<best.b<<"::"<<num<<endl;
//st=2;
//SendA(0);
//return;
//cout<<num<<"<<<<<"<<endl;
if(num==511){
SendA(0);
st=3;
}
else if(best.a==511){
SendA(1);
st=2;
}
else if(best.a<num){
SendA(0);
st=3;
}
else{
SendA(1);
st=2;
}
//////cout<<st<<"....."<<endl;
if(st==2){
return;
}
}
if(st==2){
if(x){
num2+=(1<<cur2);
}
cur2+=1;
//////cout<<cur2<<";;;;;;;;;;;;;;;"<<endl;
if(cur2==11){
last=num2;
//////cout<<num2<<"//"<<endl;
vis[last]=1;
dist[last]=num;
}
else{
return;
}
}
if(st==3){
//cout<<"hello"<<"<"<<best.b<<","<<best.a<<",,"<<endl;
dist[best.b]=best.a;
vis[best.b]=1;
// last=best.b;
////cout<<cur+1<<endl;
for(int i=0;i<9;i++){
if((1<<i)&(best.a-dist[last])){
SendA(1);
}
else{
SendA(0);
}
}
for(int i=0;i<11;i++){
if((1<<i)&best.b){
SendA(1);
}
else{
SendA(0);
}
}
last=best.b;
}
//////cout<<last<<','<<dist[last]<<endl;
st=0;
num=0;
num2=0;
cur2=0;
cur=0;
kk=0;
num=dist[last];
/* int kk=0;
for(int i=0;i<n;i++){
if(vis[i]==0){
kk=1;
}
}
if(kk){
SendA(0);
}*/
}
void InitA(int nn,int m,vector<int> aa,vector<int> bb,vector<int> cc){
n=nn;
for(int i=0;i<m;i++){
adj[aa[i]].pb({bb[i],cc[i]});
adj[bb[i]].pb({aa[i],cc[i]});
}
for(int i=1;i<n;i++){
dist[i]=-1;
}
vis[0]=1;
SendA(0);
}
/*int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#include "Baijan.h"
vector<pair<int,int>> adj2[2001];
int dist2[2001];
int st2=0;
int last2=0;
int vis2[2001];
pair<int,int> best2;
int ne;
int cur3=0;
int cur4=0;
int num3=0;
int num4=0;
int cot=0;
//int lol=0;
void ReceiveB(bool x){
if(st2==0){
for(auto j:adj2[last2]){
if(dist2[j.a]==-1 or dist2[j.a]>dist2[last2]+j.b){
dist2[j.a]=dist2[last2]+j.b;
}
}
best2={-1,-1};
for(int i=0;i<ne;i++){
if(vis2[i]==0 and dist2[i]!=-1){
if(best2.a==-1){
best2={dist2[i],i};
}
else{
if(dist2[i]<best2.a){
best2={dist2[i],i};
}
}
}
}
//cout<<best2.a<<"::"<<best2.b<<endl;
if(best2.a==-1){
best2.a=(1<<9)-1;
}
//best2.a=max(best2.a,0);
// st2=7;
st2=10;
for(int i=0;i<9;i++){
/* if(lol){
return;
}*/
// cot+=1;
if(((1<<i)&(best2.a-dist2[last2]))){
// cot+=1;
////cout<<i<<"?//////////////////"<<"<"<<st2<<endl;
SendB(1);
/* if(lol){
return;
}*/
}
else{
SendB(0);
}
}
return;
}
////cout<<st2<<"..........."<<endl;
if(st2==10){
if(x){
st2=2;
//cout<<111<<endl;
}
else{
st2=3;
return;
}
}
/* if(st2==7){
// lol=1;
//cout<<111111<<",,"<<cot<<endl;
//////cout<<cot<<endl;
for(int i=0;i<cot-1;i++){
if(((1<<(19-i))&best2.a)){
num3+=(1<<(19-i));
}
}
////cout<<111111111<<",,,"<<cot<<",,"<<num3<<endl;
cur3=cot;
st2=3;
return;
}*/
/*if(st2==1){
if(x){
st2=2;
}
else{
st2=3;
return;
}
}*/
if(st2==2){
//////cout<<1111<<endl;
st2=0;
dist2[best2.b]=best2.a;
vis2[best2.b]=1;
last2=best2.b;
for(int i=0;i<11;i++){
if((1<<i)&best2.b){
SendB(1);
}
else{
SendB(0);
}
}
}
if(st2==3){
if(cur3==0){
num3+=dist2[last2];
}
if(cur3<9){
if(x){
num3+=(1<<cur3);
}
cur3++;
return;
}
else{
if(x){
num4+=(1<<cur4);
}
cur4++;
if(cur4==11){
////cout<<num4<<"?????"<<","<<num3<<endl;
//////cout<<20<<endl;
//////cout<<num4<<",,"<<num3<<endl;
dist2[num4]=num3;
//cout<<num4<<",,,,"<<num3<<endl;
vis2[num4]=1;
last2=num4;
}
else{
return;
}
}
}
// //////cout<<last2<<"<<<>>>>"<<endl;
num3=0;
num4=0;
cur3=0;
cur4=0;
st2=0;
//lol=0;
cot=0;
int ko=0;
for(int i=0;i<ne;i++){
if(vis2[i]==0){
ko=1;
}
}
if(ko){
ReceiveB(0);
}
}
void InitB(int nn,int m,vector<int> aa,vector<int> bb,vector<int> cc){
ne=nn;
for(int i=0;i<m;i++){
adj2[aa[i]].pb({bb[i],cc[i]});
adj2[bb[i]].pb({aa[i],cc[i]});
}
for(int i=1;i<ne;i++){
dist2[i]=-1;
}
vis2[0]=1;
}
/*int main(){
ios_base::sync_with_st2dio(false);
cin.tie(NULL);
return 0;
}*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |