#include "Azer.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int dist[2010];
vector<pair<int, int>>link[2010];
int NN, AA;
int vis[2010];
int md = 0;
int cnt = 0;
int val = 0;
int curdiff = 0;
int befdiff = 0;
int curo = 0;
int lc;
int cp = 0;
int b = 0;
}
void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
std::vector<int> C)
{
memset(dist, 1, sizeof(dist));
NN = N;
AA = A;
int i;
for (i = 0; i < A; i++)
{
link[U[i]].push_back({ V[i],C[i] });
link[V[i]].push_back({ U[i],C[i] });
}
vis[0] = 1;
dist[0] = 0;
int j;
i = 0;
for (j = 0; j < link[i].size(); j++)
{
if (dist[link[i][j].first] > dist[i] + link[i][j].second)
{
dist[link[i][j].first] = dist[i] + link[i][j].second;
}
}
pair<int, int>cc = { 511,0 };
for (j = 0; j < NN; j++)
{
if (!vis[j])
cc = min(cc, { dist[j],j });
}
curdiff = cc.first;
curo = cc.second;
for (i = 0; i < 9; i++)
{
SendA((curdiff >> i) & 1);
}
}
void ReceiveA(bool x)
{
int cu = 0;
if (md == 0)
{
val += x * (1 << cnt);
cnt++;
if (cnt == 9)
{
befdiff = val;
cp++;
cnt = 0;
val = 0;
if (curdiff <= befdiff)
{
int i;
for (i = 0; i < 11; i++)
{
SendA((curo >> i) & 1);
}
cu = curo;
}
else
{
md = 1;
return;
}
}
else
return;
}
else
{
val += x * (1 << cnt);
cnt++;
if (cnt == 11)
{
dist[val] = befdiff+b;
vis[val] = 1;
cu = val;
cnt = 0;
md = 0;
val = 0;
}
else
return;
}
if (cp == NN - 1)
return;
int i=cu;
pair<int, int>cc = { 511,0 };
int j;
b = dist[i];
vis[i] = 1;
for (j = 0; j < link[i].size(); j++)
{
if (dist[link[i][j].first] > dist[i] + link[i][j].second)
{
dist[link[i][j].first] = dist[i] + link[i][j].second;
}
}
for (j = 0; j < NN; j++)
{
if (!vis[j])
cc = min(cc, { dist[j] - b,j });
}
curdiff = cc.first;
curo = cc.second;
for (i = 0; i < 9; i++)
{
SendA((curdiff >> i) & 1);
}
}
std::vector<int> Answer() {
std::vector<int> ans(NN);
for (int k = 0; k < NN; ++k) {
ans[k] = dist[k];
}
return ans;
}
#include "Baijan.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int dist2[2010];
vector<pair<int, int>>link2[2010];
int NN2, AA2;
int vis2[2010];
int md2 = 0;
int cnt2 = 0;
int val2 = 0;
int curdiff2 = 0;
int befdiff2 = 0;
int curo2 = 0;
int lc2;
int cp2 = 0;
int b2 = 0;
}
void InitB(int N, int B, std::vector<int> S, std::vector<int> T,
std::vector<int> D) {
memset(dist2, 1, sizeof(dist2));
NN2 = N;
AA2 = B;
int i;
for (i = 0; i < B; i++)
{
link2[S[i]].push_back({ T[i],D[i] });
link2[T[i]].push_back({ S[i],D[i] });
}
vis2[0] = 1;
dist2[0] = 0;
int j;
i = 0;
for (j = 0; j < link2[i].size(); j++)
{
if (dist2[link2[i][j].first] > dist2[i] + link2[i][j].second)
{
dist2[link2[i][j].first] = dist2[i] + link2[i][j].second;
}
}
pair<int, int>cc = { 511,0 };
for (j = 0; j < NN2; j++)
{
if (!vis2[j])
cc = min(cc, { dist2[j],j });
}
curdiff2 = cc.first;
curo2 = cc.second;
for (i = 0; i < 9; i++)
{
SendB((curdiff2 >> i) & 1);
}
}
void ReceiveB(bool y) {
int cu = 0;
if (md2 == 0)
{
val2 += y * (1 << cnt2);
cnt2++;
if (cnt2 == 9)
{
befdiff2 = val2;
cp2++;
cnt2 = 0;
val2 = 0;
if (curdiff2 < befdiff2)
{
int i;
for (i = 0; i < 11; i++)
{
SendB((curo2 >> i) & 1);
}
cu = curo2;
}
else
{
md2 = 1;
return;
}
}
else
return;
}
else
{
val2 += y * (1 << cnt2);
cnt2++;
if (cnt2 == 11)
{
dist2[val2] = befdiff2+b2;
vis2[val2] = 1;
cu = val2;
cnt2 = 0;
md2 = 0;
val2 = 0;
}
else
return;
}
if (cp2 == NN2 - 1)
return;
int i = cu;
pair<int, int>cc = { 511,0 };
int j;
b2 = dist2[i];
vis2[i] = 1;
for (j = 0; j < link2[i].size(); j++)
{
if (dist2[link2[i][j].first] > dist2[i] + link2[i][j].second)
{
dist2[link2[i][j].first] = dist2[i] + link2[i][j].second;
}
}
for (j = 0; j < NN2; j++)
{
if (!vis2[j])
cc = min(cc, { dist2[j] - b2,j });
}
curdiff2 = cc.first;
curo2 = cc.second;
for (i = 0; i < 9; i++)
{
SendB((curdiff2 >> i) & 1);
}
}
Compilation message
Azer.cpp: In function 'void InitA(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Azer.cpp:36:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (j = 0; j < link[i].size(); j++)
| ~~^~~~~~~~~~~~~~~~
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:112:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for (j = 0; j < link[i].size(); j++)
| ~~^~~~~~~~~~~~~~~~
Azer.cpp: At global scope:
Azer.cpp:15:6: warning: '{anonymous}::lc' defined but not used [-Wunused-variable]
15 | int lc;
| ^~
Baijan.cpp: In function 'void InitB(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Baijan.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (j = 0; j < link2[i].size(); j++)
| ~~^~~~~~~~~~~~~~~~~
Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:109:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (j = 0; j < link2[i].size(); j++)
| ~~^~~~~~~~~~~~~~~~~
Baijan.cpp: At global scope:
Baijan.cpp:15:6: warning: '{anonymous}::lc2' defined but not used [-Wunused-variable]
15 | int lc2;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
540 ms |
812 KB |
Output is correct |
2 |
Runtime error |
161 ms |
336 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
170 ms |
336 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
444 ms |
740 KB |
Output is correct |
2 |
Runtime error |
190 ms |
340 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
692 KB |
Output is correct |
2 |
Correct |
247 ms |
684 KB |
Output is correct |
3 |
Correct |
354 ms |
13308 KB |
Output is correct |
4 |
Correct |
270 ms |
756 KB |
Output is correct |
5 |
Correct |
314 ms |
10068 KB |
Output is correct |
6 |
Correct |
257 ms |
720 KB |
Output is correct |
7 |
Correct |
234 ms |
748 KB |
Output is correct |
8 |
Correct |
216 ms |
776 KB |
Output is correct |
9 |
Correct |
291 ms |
18072 KB |
Output is correct |
10 |
Correct |
361 ms |
18232 KB |
Output is correct |
11 |
Correct |
476 ms |
35660 KB |
Output is correct |
12 |
Correct |
409 ms |
30648 KB |
Output is correct |
13 |
Correct |
243 ms |
656 KB |
Output is correct |
14 |
Runtime error |
181 ms |
332 KB |
Execution killed with signal 13 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
692 KB |
Output is correct |
2 |
Correct |
247 ms |
684 KB |
Output is correct |
3 |
Correct |
354 ms |
13308 KB |
Output is correct |
4 |
Correct |
270 ms |
756 KB |
Output is correct |
5 |
Correct |
314 ms |
10068 KB |
Output is correct |
6 |
Correct |
257 ms |
720 KB |
Output is correct |
7 |
Correct |
234 ms |
748 KB |
Output is correct |
8 |
Correct |
216 ms |
776 KB |
Output is correct |
9 |
Correct |
291 ms |
18072 KB |
Output is correct |
10 |
Correct |
361 ms |
18232 KB |
Output is correct |
11 |
Correct |
476 ms |
35660 KB |
Output is correct |
12 |
Correct |
409 ms |
30648 KB |
Output is correct |
13 |
Correct |
243 ms |
656 KB |
Output is correct |
14 |
Runtime error |
181 ms |
332 KB |
Execution killed with signal 13 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
692 KB |
Output is correct |
2 |
Correct |
247 ms |
684 KB |
Output is correct |
3 |
Correct |
354 ms |
13308 KB |
Output is correct |
4 |
Correct |
270 ms |
756 KB |
Output is correct |
5 |
Correct |
314 ms |
10068 KB |
Output is correct |
6 |
Correct |
257 ms |
720 KB |
Output is correct |
7 |
Correct |
234 ms |
748 KB |
Output is correct |
8 |
Correct |
216 ms |
776 KB |
Output is correct |
9 |
Correct |
291 ms |
18072 KB |
Output is correct |
10 |
Correct |
361 ms |
18232 KB |
Output is correct |
11 |
Correct |
476 ms |
35660 KB |
Output is correct |
12 |
Correct |
409 ms |
30648 KB |
Output is correct |
13 |
Correct |
243 ms |
656 KB |
Output is correct |
14 |
Runtime error |
181 ms |
332 KB |
Execution killed with signal 13 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
540 ms |
812 KB |
Output is correct |
2 |
Runtime error |
161 ms |
336 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |