이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "Azer.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
namespace {
const int inf=1e9;
const int mxn=5e5+5;
int n;
vector<pair<int,int>> adj[mxn];
int cur=0;
int bit=0;
int prv=0;
int sir=0;
vector<int> d;
vector<bool> vis;
pair<int,int> mn={inf,inf};
void send(int x,int len){
for(int i=len-1;i>=0;i--){
if(x&(1<<len)){
SendA(1);
}
else{
SendA(0);
}
}
}
void relax(){
d[mn.s]=prv+mn.f;
prv=d[mn.s];
vis[mn.s]=true;
for(auto u:adj[mn.s]){
d[u.f]=min(d[u.f],d[mn.s]+u.s);
}
cerr<<"A:"<<'\n';
for(int i=0;i<n;i++){
cerr<<d[i]<<' ';
}
cerr<<'\n';
mn={inf,inf};
for(int i=0;i<n;i++){
if(vis[i]) continue;
mn=min(mn,{d[i]-prv,i});
}
if(mn.f!=inf){
send(mn.f,9);
}
}
void getdis(){
if(cur==511){
send(mn.s,11);
relax();
cur=bit=0;
}
else{
mn.f=cur;
bit=cur=0;
sir=1;
}
}
void getid(){
mn.s=cur;
relax();
bit=cur=0;
sir=0;
}
} // namespace
void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
std::vector<int> C) {
n=N;
for(int i=0;i<A;i++){
int a=U[i];
int b=V[i];
int c=C[i];
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
d=vector<int>(n,inf);
vis=vector<bool>(n,false);
d[0]=0;
vis[0]=true;
for(auto u:adj[0]){
d[u.f]=min(d[u.f],d[0]+u.s);
}
for(int i=0;i<n;i++){
if(vis[i]) continue;
mn=min(mn,{d[i]-prv,i});
}
send(mn.f,9);
}
void ReceiveA(bool x) {
cur=cur*2+x;
bit++;
if(bit==9 and sir==0){
getdis();
}
else if(bit==11){
getid();
}
}
std::vector<int> Answer() {
return d;
}
#include "Baijan.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
namespace {
const int inf=1e9;
const int mxn=5e5+5;
int n;
vector<pair<int,int>> adj[mxn];
int cur=0;
int bit=0;
int prv=0;
int sir=0;
vector<int> d;
vector<bool> vis;
pair<int,int> mn={inf,inf};
void send(int x,int len){
for(int i=len-1;i>=0;i--){
if(x&(1<<len)){
SendB(1);
}
else{
SendB(0);
}
}
}
void relax(){
d[mn.s]=prv+mn.f;
prv=d[mn.s];
vis[mn.s]=true;
for(auto u:adj[mn.s]){
d[u.f]=min(d[u.f],d[mn.s]+u.s);
}
mn={inf,inf};
for(int i=0;i<n;i++){
if(vis[i]) continue;
mn=min(mn,{d[i]-prv,i});
}
}
void getdis(){
if(mn.f>cur){
send(511,9);
cur=bit=0;
sir=1;
}
else{
send(mn.f,9);
send(mn.s,11);
relax();
cur=bit=0;
}
}
void getid(){
mn.s=cur;
relax();
bit=cur=0;
sir=0;
}
} // namespace
void InitB(int N, int B, std::vector<int> U, std::vector<int> V,
std::vector<int> C) {
n=N;
for(int i=0;i<B;i++){
int a=U[i];
int b=V[i];
int c=C[i];
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
d=vector<int>(n,inf);
vis=vector<bool>(n,false);
d[0]=0;
vis[0]=true;
for(auto u:adj[0]){
d[u.f]=min(d[u.f],d[0]+u.s);
}
for(int i=0;i<n;i++){
if(vis[i]) continue;
mn=min(mn,{d[i]-prv,i});
}
}
void ReceiveB(bool x) {
cur=cur*2+x;
bit++;
if(bit==9 and sir==0){
getdis();
}
else if(bit==11){
getid();
}
}
# | 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... |