#include "Azer.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
using pi = pair<int, int>;
namespace {
vector<pi> gph[MAXN];
int dist[MAXN];
bool vis[MAXN];
bool firstSkip = 1;
int n, recValue1, recValue2, curMode;
void sendValue(int x, int b){
for(int i=b-1; i>=0; i--){
SendA((x >> i) & 1);
}
}
void relax(int v){
// printf("A relaxed %d = %d\n", v, dist[v]);
vis[v] = 1;
for(auto &i : gph[v]){
dist[i.second] = min(dist[i.second], i.first + dist[v]);
}
}
int getMax(){
int ret = 0;
for(int i=0; i<n; i++){
if(vis[i]) ret = max(ret, dist[i]);
}
return ret;
}
} // 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++){
gph[U[i]].emplace_back(C[i], V[i]);
gph[V[i]].emplace_back(C[i], U[i]);
}
memset(dist, 0x3f, sizeof(dist));
dist[0] = 0;
}
void ReceiveA(bool x) {
if(curMode == 0){
curMode = 69;
if(count(vis, vis + n, 1) == n) return;
int cur = 1048575, pos = -1;
for(int i=0; i<n; i++){
if(!vis[i] && dist[i] < cur){
cur = dist[i];
pos = i;
}
}
cur -= getMax();
cur = min(cur, 511);
sendValue(cur, 9 - firstSkip);
firstSkip = 0;
return;
}
if(curMode >= 69){
if(curMode < 80){
recValue1 = recValue1 * 2 + x;
}
else{
recValue2 = recValue2 * 2 + x;
}
curMode++;
if(curMode == 77 && recValue1 == 255){
int cur = 1048575, pos = -1;
for(int i=0; i<n; i++){
if(!vis[i] && dist[i] < cur){
cur = dist[i];
pos = i;
}
}
relax(pos);
sendValue(pos, 11);
curMode = 0;
recValue1 = recValue2 = 0;
}
if(curMode == 89){
dist[recValue1] = min(dist[recValue1], recValue2 + getMax());
relax(recValue1);
recValue1 = recValue2 = 0;
curMode = 0;
ReceiveA(0);
}
}
}
vector<int> Answer(){
vector<int> v(dist, dist + n);
return v;
}
#include "Baijan.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
using pi = pair<int, int>;
namespace {
vector<pi> gph[MAXN];
int dist[MAXN];
bool vis[MAXN];
int n, recValue, recValue2, curMode;
bool firstSkip = 1;
void sendValue(int x, int b){
for(int i=b-1; i>=0; i--){
SendB((x >> i) & 1);
}
}
void relax(int v){
// printf("B relaxed %d = %d\n", v, dist[v]);
vis[v] = 1;
for(auto &i : gph[v]){
dist[i.second] = min(dist[i.second], i.first + dist[v]);
}
}
int getMax(){
int ret = 0;
for(int i=0; i<n; i++){
if(vis[i]) ret = max(ret, dist[i]);
}
return ret;
}
} // namespace
void InitB(int N, int B, std::vector<int> S, std::vector<int> T,
std::vector<int> D) {
n = N;
for(int i=0; i<B; i++){
gph[S[i]].emplace_back(D[i], T[i]);
gph[T[i]].emplace_back(D[i], S[i]);
}
memset(dist, 0x3f, sizeof(dist));
dist[0] = 0;
SendB(0);
}
void ReceiveB(bool y) {
if(curMode < 9 - firstSkip){
curMode++;
recValue = recValue * 2 + y;
}
if(curMode < 9 - firstSkip) return;
if(curMode > 999){
curMode++;
recValue2 = recValue2 * 2 + y;
if(curMode >= 1011){
dist[recValue2] = min(dist[recValue2], recValue + getMax());
relax(recValue2);
recValue = recValue2 = 0;
curMode = 0;
SendB(0);
}
return;
}
firstSkip = 0;
int cur = 1048575, pos = -1;
for(int i=0; i<n; i++){
if(!vis[i] && dist[i] < cur){
cur = dist[i];
pos = i;
}
}
cur -= getMax();
int another_dist = recValue;
if(cur > another_dist){
sendValue(255, 8);
curMode = 1000;
// beg A to answer the vertex number
}
else{
relax(pos);
curMode = 0;
recValue = recValue2 = 0;
sendValue(pos, 11);
sendValue(cur, 9);
// tell A that vertex number with its distance
}
}
Compilation message
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:50:22: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
int cur = 1048575, pos = -1;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1030 ms |
1600 KB |
Output is correct |
2 |
Correct |
8 ms |
1064 KB |
Output is correct |
3 |
Correct |
1212 ms |
1536 KB |
Output is correct |
4 |
Correct |
1512 ms |
20088 KB |
Output is correct |
5 |
Correct |
84 ms |
1360 KB |
Output is correct |
6 |
Correct |
1174 ms |
4320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1088 KB |
Output is correct |
2 |
Correct |
1200 ms |
1504 KB |
Output is correct |
3 |
Correct |
1280 ms |
1760 KB |
Output is correct |
4 |
Correct |
1590 ms |
55208 KB |
Output is correct |
5 |
Correct |
1598 ms |
48056 KB |
Output is correct |
6 |
Correct |
182 ms |
1504 KB |
Output is correct |
7 |
Correct |
1776 ms |
48216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1193 ms |
1760 KB |
Output is correct |
2 |
Correct |
32 ms |
1344 KB |
Output is correct |
3 |
Correct |
1186 ms |
1504 KB |
Output is correct |
4 |
Correct |
1262 ms |
1600 KB |
Output is correct |
5 |
Correct |
1234 ms |
1664 KB |
Output is correct |
6 |
Correct |
1074 ms |
1576 KB |
Output is correct |
7 |
Correct |
1294 ms |
1856 KB |
Output is correct |
8 |
Correct |
1104 ms |
1344 KB |
Output is correct |
9 |
Correct |
1340 ms |
1504 KB |
Output is correct |
10 |
Correct |
1228 ms |
1504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
568 ms |
1760 KB |
Output is correct |
2 |
Correct |
374 ms |
1248 KB |
Output is correct |
3 |
Correct |
632 ms |
23592 KB |
Output is correct |
4 |
Correct |
532 ms |
1504 KB |
Output is correct |
5 |
Correct |
742 ms |
17288 KB |
Output is correct |
6 |
Correct |
562 ms |
1504 KB |
Output is correct |
7 |
Correct |
456 ms |
1672 KB |
Output is correct |
8 |
Correct |
520 ms |
1504 KB |
Output is correct |
9 |
Correct |
828 ms |
35792 KB |
Output is correct |
10 |
Correct |
904 ms |
36048 KB |
Output is correct |
11 |
Correct |
1032 ms |
61112 KB |
Output is correct |
12 |
Correct |
922 ms |
53448 KB |
Output is correct |
13 |
Correct |
520 ms |
1768 KB |
Output is correct |
14 |
Correct |
4 ms |
976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
568 ms |
1760 KB |
Output is correct |
2 |
Correct |
374 ms |
1248 KB |
Output is correct |
3 |
Correct |
632 ms |
23592 KB |
Output is correct |
4 |
Correct |
532 ms |
1504 KB |
Output is correct |
5 |
Correct |
742 ms |
17288 KB |
Output is correct |
6 |
Correct |
562 ms |
1504 KB |
Output is correct |
7 |
Correct |
456 ms |
1672 KB |
Output is correct |
8 |
Correct |
520 ms |
1504 KB |
Output is correct |
9 |
Correct |
828 ms |
35792 KB |
Output is correct |
10 |
Correct |
904 ms |
36048 KB |
Output is correct |
11 |
Correct |
1032 ms |
61112 KB |
Output is correct |
12 |
Correct |
922 ms |
53448 KB |
Output is correct |
13 |
Correct |
520 ms |
1768 KB |
Output is correct |
14 |
Correct |
4 ms |
976 KB |
Output is correct |
15 |
Correct |
682 ms |
1504 KB |
Output is correct |
16 |
Correct |
667 ms |
1400 KB |
Output is correct |
17 |
Correct |
691 ms |
1360 KB |
Output is correct |
18 |
Correct |
716 ms |
17552 KB |
Output is correct |
19 |
Correct |
602 ms |
1504 KB |
Output is correct |
20 |
Correct |
844 ms |
17912 KB |
Output is correct |
21 |
Correct |
738 ms |
1672 KB |
Output is correct |
22 |
Correct |
706 ms |
1584 KB |
Output is correct |
23 |
Correct |
1162 ms |
44208 KB |
Output is correct |
24 |
Correct |
1066 ms |
43728 KB |
Output is correct |
25 |
Correct |
1502 ms |
75120 KB |
Output is correct |
26 |
Correct |
1258 ms |
64400 KB |
Output is correct |
27 |
Correct |
553 ms |
1672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
568 ms |
1760 KB |
Output is correct |
2 |
Correct |
374 ms |
1248 KB |
Output is correct |
3 |
Correct |
632 ms |
23592 KB |
Output is correct |
4 |
Correct |
532 ms |
1504 KB |
Output is correct |
5 |
Correct |
742 ms |
17288 KB |
Output is correct |
6 |
Correct |
562 ms |
1504 KB |
Output is correct |
7 |
Correct |
456 ms |
1672 KB |
Output is correct |
8 |
Correct |
520 ms |
1504 KB |
Output is correct |
9 |
Correct |
828 ms |
35792 KB |
Output is correct |
10 |
Correct |
904 ms |
36048 KB |
Output is correct |
11 |
Correct |
1032 ms |
61112 KB |
Output is correct |
12 |
Correct |
922 ms |
53448 KB |
Output is correct |
13 |
Correct |
520 ms |
1768 KB |
Output is correct |
14 |
Correct |
4 ms |
976 KB |
Output is correct |
15 |
Correct |
682 ms |
1504 KB |
Output is correct |
16 |
Correct |
667 ms |
1400 KB |
Output is correct |
17 |
Correct |
691 ms |
1360 KB |
Output is correct |
18 |
Correct |
716 ms |
17552 KB |
Output is correct |
19 |
Correct |
602 ms |
1504 KB |
Output is correct |
20 |
Correct |
844 ms |
17912 KB |
Output is correct |
21 |
Correct |
738 ms |
1672 KB |
Output is correct |
22 |
Correct |
706 ms |
1584 KB |
Output is correct |
23 |
Correct |
1162 ms |
44208 KB |
Output is correct |
24 |
Correct |
1066 ms |
43728 KB |
Output is correct |
25 |
Correct |
1502 ms |
75120 KB |
Output is correct |
26 |
Correct |
1258 ms |
64400 KB |
Output is correct |
27 |
Correct |
553 ms |
1672 KB |
Output is correct |
28 |
Correct |
744 ms |
1328 KB |
Output is correct |
29 |
Correct |
756 ms |
1344 KB |
Output is correct |
30 |
Correct |
1204 ms |
42176 KB |
Output is correct |
31 |
Correct |
842 ms |
1576 KB |
Output is correct |
32 |
Correct |
1170 ms |
37296 KB |
Output is correct |
33 |
Correct |
700 ms |
1496 KB |
Output is correct |
34 |
Correct |
720 ms |
1832 KB |
Output is correct |
35 |
Correct |
674 ms |
1688 KB |
Output is correct |
36 |
Correct |
1314 ms |
49240 KB |
Output is correct |
37 |
Correct |
1230 ms |
49360 KB |
Output is correct |
38 |
Correct |
1580 ms |
85344 KB |
Output is correct |
39 |
Correct |
1584 ms |
78392 KB |
Output is correct |
40 |
Correct |
876 ms |
2016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1030 ms |
1600 KB |
Output is correct |
2 |
Correct |
8 ms |
1064 KB |
Output is correct |
3 |
Correct |
1212 ms |
1536 KB |
Output is correct |
4 |
Correct |
1512 ms |
20088 KB |
Output is correct |
5 |
Correct |
84 ms |
1360 KB |
Output is correct |
6 |
Correct |
1174 ms |
4320 KB |
Output is correct |
7 |
Correct |
6 ms |
1088 KB |
Output is correct |
8 |
Correct |
1200 ms |
1504 KB |
Output is correct |
9 |
Correct |
1280 ms |
1760 KB |
Output is correct |
10 |
Correct |
1590 ms |
55208 KB |
Output is correct |
11 |
Correct |
1598 ms |
48056 KB |
Output is correct |
12 |
Correct |
182 ms |
1504 KB |
Output is correct |
13 |
Correct |
1776 ms |
48216 KB |
Output is correct |
14 |
Correct |
1193 ms |
1760 KB |
Output is correct |
15 |
Correct |
32 ms |
1344 KB |
Output is correct |
16 |
Correct |
1186 ms |
1504 KB |
Output is correct |
17 |
Correct |
1262 ms |
1600 KB |
Output is correct |
18 |
Correct |
1234 ms |
1664 KB |
Output is correct |
19 |
Correct |
1074 ms |
1576 KB |
Output is correct |
20 |
Correct |
1294 ms |
1856 KB |
Output is correct |
21 |
Correct |
1104 ms |
1344 KB |
Output is correct |
22 |
Correct |
1340 ms |
1504 KB |
Output is correct |
23 |
Correct |
1228 ms |
1504 KB |
Output is correct |
24 |
Correct |
568 ms |
1760 KB |
Output is correct |
25 |
Correct |
374 ms |
1248 KB |
Output is correct |
26 |
Correct |
632 ms |
23592 KB |
Output is correct |
27 |
Correct |
532 ms |
1504 KB |
Output is correct |
28 |
Correct |
742 ms |
17288 KB |
Output is correct |
29 |
Correct |
562 ms |
1504 KB |
Output is correct |
30 |
Correct |
456 ms |
1672 KB |
Output is correct |
31 |
Correct |
520 ms |
1504 KB |
Output is correct |
32 |
Correct |
828 ms |
35792 KB |
Output is correct |
33 |
Correct |
904 ms |
36048 KB |
Output is correct |
34 |
Correct |
1032 ms |
61112 KB |
Output is correct |
35 |
Correct |
922 ms |
53448 KB |
Output is correct |
36 |
Correct |
520 ms |
1768 KB |
Output is correct |
37 |
Correct |
4 ms |
976 KB |
Output is correct |
38 |
Correct |
682 ms |
1504 KB |
Output is correct |
39 |
Correct |
667 ms |
1400 KB |
Output is correct |
40 |
Correct |
691 ms |
1360 KB |
Output is correct |
41 |
Correct |
716 ms |
17552 KB |
Output is correct |
42 |
Correct |
602 ms |
1504 KB |
Output is correct |
43 |
Correct |
844 ms |
17912 KB |
Output is correct |
44 |
Correct |
738 ms |
1672 KB |
Output is correct |
45 |
Correct |
706 ms |
1584 KB |
Output is correct |
46 |
Correct |
1162 ms |
44208 KB |
Output is correct |
47 |
Correct |
1066 ms |
43728 KB |
Output is correct |
48 |
Correct |
1502 ms |
75120 KB |
Output is correct |
49 |
Correct |
1258 ms |
64400 KB |
Output is correct |
50 |
Correct |
553 ms |
1672 KB |
Output is correct |
51 |
Correct |
744 ms |
1328 KB |
Output is correct |
52 |
Correct |
756 ms |
1344 KB |
Output is correct |
53 |
Correct |
1204 ms |
42176 KB |
Output is correct |
54 |
Correct |
842 ms |
1576 KB |
Output is correct |
55 |
Correct |
1170 ms |
37296 KB |
Output is correct |
56 |
Correct |
700 ms |
1496 KB |
Output is correct |
57 |
Correct |
720 ms |
1832 KB |
Output is correct |
58 |
Correct |
674 ms |
1688 KB |
Output is correct |
59 |
Correct |
1314 ms |
49240 KB |
Output is correct |
60 |
Correct |
1230 ms |
49360 KB |
Output is correct |
61 |
Correct |
1580 ms |
85344 KB |
Output is correct |
62 |
Correct |
1584 ms |
78392 KB |
Output is correct |
63 |
Correct |
876 ms |
2016 KB |
Output is correct |
64 |
Correct |
1328 ms |
1888 KB |
Output is correct |
65 |
Correct |
1598 ms |
46648 KB |
Output is correct |
66 |
Correct |
1628 ms |
40976 KB |
Output is correct |
67 |
Correct |
1194 ms |
2048 KB |
Output is correct |
68 |
Correct |
1344 ms |
1752 KB |
Output is correct |
69 |
Correct |
2106 ms |
83240 KB |
Output is correct |
70 |
Correct |
2099 ms |
67984 KB |
Output is correct |
71 |
Correct |
1388 ms |
8832 KB |
Output is correct |
72 |
Correct |
1396 ms |
2448 KB |
Output is correct |