이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "Azer.h"
#define pb push_back
#define ss second
#define ff first
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef int64_t lld;
typedef pair<int, int> pii;
namespace {
priority_queue<pii, vector<pii>, greater<pii>> pq;
vector<vector<pii>> G;
vector<int> dist;
const int POINT = 11, WEIGHT = 9;
int pending = 0;
bool pendF = false; // true: POINT, false: WEIGHT
void pend(int len){
assert(pending == 0);
pendF = (len == POINT);
pending = len;
//cerr << "Azer: pend" << endl;
}
void send(int x, int len){
for(int i = len-1; i >= 0; i--)
SendA((x>>i)&1);
//cerr << "Azer: send " << x << endl;
}
int cur = 0;
void bfs(pii p){
assert(!dist[p.ss]);
dist[p.ss] = p.ff;
//cerr << "BFS" << p.ss << " " << p.ff << endl;
for(auto i: G[p.ss]){
if(dist[i.ss])
continue;
pq.push({i.ff+p.ff, i.ss});
}
while(!pq.empty() && dist[pq.top().ss])pq.pop();
if(pq.empty())send(505, WEIGHT);
else send(pq.top().ff-cur, WEIGHT);
pend(WEIGHT);
}
void receiveWeight(int w){
if(!pq.empty() && w + cur > pq.top().ff){
cur = pq.top().ff;
assert(!dist[pq.top().ss]);
send(pq.top().ss, POINT);
auto a = pq.top(); pq.pop();
bfs(a);
}else{
if(w == 505)return;
cur += w;
pend(POINT);
}
}
void receivePoint(int x){
bfs({cur, x});
}
};
void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) {
G.resize(N);
dist.resize(N);
for(int i = 0; i < A; i++){
G[U[i]].pb({C[i], V[i]});
G[V[i]].pb({C[i], U[i]});
}
bfs({1, 0});
}
void ReceiveA(bool x){
static int cc = 0;
cc = (cc<<1)+x;
if(--pending)return;
//cerr << "Azer: rece " << cc << endl;
pendF?receivePoint(cc):receiveWeight(cc);
cc = 0;
}
vector<int> Answer(){
for(auto& i: dist)i--;
return dist;
}
#include<bits/stdc++.h>
#include "Baijan.h"
#define pb push_back
#define ss second
#define ff first
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef int64_t lld;
typedef pair<int, int> pii;
namespace {
priority_queue<pii, vector<pii>, greater<pii>> pq;
vector<vector<pii>> G;
vector<int> dist;
const int POINT = 11, WEIGHT = 9;
int pending = 0;
bool pendF = false; // true: POINT, false: WEIGHT
void pend(int len){
assert(pending == 0);
pendF = (len == POINT);
pending = len;
//cerr << "Baij: pend" << endl;
}
void send(int x, int len){
for(int i = len-1; i >= 0; i--)
SendB((x>>i)&1);
//cerr << "Baij: send " << x << endl;
}
int cur = 0;
void bfs(pii p){
assert(!dist[p.ss]);
dist[p.ss] = p.ff;
for(auto i: G[p.ss]){
if(dist[i.ss])
continue;
pq.push({i.ff+p.ff, i.ss});
}
while(!pq.empty() && dist[pq.top().ss])pq.pop();
if(pq.empty())send(505, WEIGHT);
else send(pq.top().ff-cur, WEIGHT);
pend(WEIGHT);
}
void receiveWeight(int w){
if(!pq.empty() && w + cur >= pq.top().ff){
cur = pq.top().ff;
assert(!dist[pq.top().ss]);
send(pq.top().ss, POINT);
auto a = pq.top(); pq.pop();
bfs(a);
}else{
if(w == 505)return;
cur += w;
pend(POINT);
}
}
void receivePoint(int x){
bfs({cur, x});
}
};
void InitB(int N, int B, vector<int> U, vector<int> V, vector<int> C) {
G.resize(N);
dist.resize(N);
for(int i = 0; i < B; i++){
G[U[i]].pb({C[i], V[i]});
G[V[i]].pb({C[i], U[i]});
}
bfs({1, 0});
}
void ReceiveB(bool x){
static int cc = 0;
cc = (cc<<1)+x;
if(--pending)return;
//cerr << "Baij: rece " << cc << endl;
pendF?receivePoint(cc):receiveWeight(cc);
cc = 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... |