# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
409762 | wittydolphin | Two Transportations (JOI19_transportations) | C++14 | 0 ms | 0 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 <iostream>
#include <vector>
#include <bitset>
#include "Azer.h"
using namespace std;
int COST=0;
const int INF=1000000000;
int received=0;
int count=0;
int dist;
vector <int> Ans;
vector <int> Answer(){
return Ans;
}
void SendA(bool x);
void RecieveA(bool x){
if(x){
received*=2;
received+=1;
}else{
received*=2;
}
count++;
if(count==9){
dist=received;
received=0;
}
}
void InitA(int N, int A, vector <int> U,vector <int> V,vector <int> C){
vector <int> visited(N,0);
vector <int> distance(N,INF);
distance[0]=0;
int grid[N][N];
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
grid[i][j]=INF;
}
}
for(int i=0;i<A;i++){
grid[U[i]][V[i]]=C[i];
grid[V[i]][U[i]]=C[i];
}
for(int i=0;i<N;i++){
int min_index=-1;
int min=INF;
for(int j=0;j<N;j++){
if(visited[j]==0&&min>distance[j]){
min=distance[j];
min_index=j;
}
}
if(min_index==-1){break;}
if(min-COST>dist){//Bus is better
COST+=dist;
for(int k=0;k<9;k++){
SendA(1);
}//this is 511
while(count<20){;}
count=0;
//received is now place
distance[received]=COST;
visited[received]=1;
for(int j=0;j<N;j++){
if(visited[j]==0&&distance[j]>COST+grid[received][j]){
distance[j]=COST+grid[received][j];//renew distances
}
}
}else{
int dif=min-COST;//our one is better
COST+=dif;
bitset <9> sender(dif);
for(int k=0;k<9;k++){
SendA(sender[k]);
}
bitset <11> place(min_index);
for(int k=0;k<11;k++){
SendA(place[k]);
}
distance[min_index]=COST;
visited[min_index]=1;
for(int j=0;j<N;j++){
if(visited[j]==0&&distance[j]>COST+grid[min_index][j]){
distance[j]=COST+grid[min_index][j];//renew distances
}
}
}
}
for(int i=0;i<N;i++){
Ans.push_back(distance[i]);
}
}
#include <iostream>
#include <vector>
#include <bitset>
#include "Baijan.h"
using namespace std;
int COST=0;
const int INF=1000000000;
int dist;
int received=0;
int counter=0;
void RecieveB(bool x){
if(x){
received*=2;
received+=1;
}else{
received*=2;
}
counter++;
if(counter==9){
dist=received;
received=0;
}
}
void SendB(bool x);
void InitB(int N, int A, vector <int> S,vector <int> T,vector <int> D){
vector <int> visited(N,0);
vector <int> distance(N,INF);
distance[0]=0;
int grid[N][N];
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
grid[i][j]=INF;
}
}
for(int i=0;i<A;i++){
grid[S[i]][T[i]]=D[i];
grid[T[i]][S[i]]=D[i];
}
for(int i=0;i<N;i++){
int min_index=-1;
int min=INF;
for(int j=0;j<N;j++){
if(visited[j]==0&&min>distance[j]){
min=distance[j];
min_index=j;
}
}
if(min_index==-1){break;}
int dif=min-COST;
bitset <9> sender(dif);
for(int k=0;k<9;k++){
SendB(sender[k]);
}
while(counter<9){;}
if(dist==511){///this should happen in received
counter=0;
bitset <11> place(min_index);
for(int k=0;k<11;k++){
SendB(place[k]);
}
COST+=dif;
visited[min_index]=1;
for(int j=0;j<N;j++){
if(visited[j]==0&&distance[j]>COST+grid[min_index][j]){
distance[j]=COST+grid[min_index][j];//renew distances
}
}
}else{
COST+=dist;
//received is
while(counter<20){;}
counter=0;
distance[received]=COST;
visited[received]=1;
for(int j=0;j<N;j++){
if(visited[j]==0&&distance[j]>COST+grid[received][j]){
distance[j]=COST+grid[received][j];//renew distances
}
}
received=0;
}
}
}