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 "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
std::vector<int> Mark(int N, int M, int A, int B,
std::vector<int> U, std::vector<int> V)
{
vector<vector<ii>> ADJ(N);
map<ii, int> paths;
vector<bool> filled(M, false);
for (int i = 0; i < M; i++) {
ADJ[U[i]].push_back({V[i], i});
ADJ[V[i]].push_back({U[i], i});
paths[{U[i], V[i]}] = i;
paths[{V[i], U[i]}] = i;
}
std::vector<int> X(M);
priority_queue<ii, vector<ii>, greater<ii>> q;
vector<int> prevNode(N, -1);
vector<int> shortest(N, 1e8);
shortest[0] = 0;
q.push({0,0});
while (!q.empty()) {
auto [dis, pos] = q.top();
q.pop();
if (dis != shortest[pos]) continue;
for (auto [conn, _] : ADJ[pos]) {
if (dis+1 < shortest[conn]) {
shortest[conn] = dis+1;
prevNode[conn] = pos;
q.push({dis+1, conn});
}
}
}
for (int p = 1; p < N; p++) {
X[paths[{p, prevNode[p]}]] = shortest[p]%(A==2?2:3);
filled[paths[{p, prevNode[p]}]] = true;
}
for (int i = 0; i < M; i++) if (!filled[i]) {
X[i] = (min(shortest[U[i]], shortest[V[i]])+1)%(A==2?2:3);
}
return X;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
int A, B;
int prevA = 0;
bool onPath = false;
bool first = true;
int pathAmount(vector<int> y) {
int sum = 1;
for (int el : y) sum += el;
return sum;
}
} // namespace
void Init(int A, int B)
{
::A = A;
::B = B;
}
int Move(std::vector<int> y)
{
if (A==2) {
if (!::onPath) {
if (::first) {
::first = false;
if (::pathAmount(y) != 3) {
::prevA = (y[0] == 1 ? 0 : 1);
::onPath = true;
return (y[0] == 1 ? 0 : 1);
}
return 0;
}
if (::pathAmount(y) > 2) {
::prevA = (y[0] == 1 ? 0 : (y[1] == 1 ? 1 : ::prevA));
::onPath = true;
return (y[0] == 1 ? 0 : (y[1] == 1 ? 1 : -1));
} else {
::prevA = !::prevA;
return ::prevA;
}
} else {
::prevA = !::prevA;
return ::prevA;
}
} else {
if ((::pathAmount(y) > (first?3:2)) || (::pathAmount(y) == 2 && first)) {
first = false;
int corr;
for (int p = 0 ; p < y.size(); p++) if (y[p] == 1) {
corr = p;
break;
}
return corr;
}
else {
first = false;
int corr = -1;
for (int p = 0 ; p < y.size(); p++) if (y[p] && (corr==-1 || (corr==0&&p==y.size()-1))) corr = p;
return corr;
}
}
return -1;
}
Compilation message (stderr)
Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:57:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int p = 0 ; p < y.size(); p++) if (y[p] == 1) {
| ~~^~~~~~~~~~
Catherine.cpp:66:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int p = 0 ; p < y.size(); p++) if (y[p] && (corr==-1 || (corr==0&&p==y.size()-1))) corr = p;
| ~~^~~~~~~~~~
Catherine.cpp:66:85: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int p = 0 ; p < y.size(); p++) if (y[p] && (corr==-1 || (corr==0&&p==y.size()-1))) corr = p;
| ~^~~~~~~~~~~~
Catherine.cpp:56:17: warning: 'corr' may be used uninitialized in this function [-Wmaybe-uninitialized]
56 | int corr;
| ^~~~
# | 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... |