# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
634437 | PixelCat | Flights (JOI22_flights) | C++17 | 1 ms | 456 KiB |
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 "Ali.h"
#include <string>
#include <vector>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
using namespace std;
namespace {
const int MAXN = 10010;
vector<int> adj[MAXN];
string tree;
int cnt;
void buildTree(int n, int p) {
// SetID(n, cnt);
cnt++;
tree.push_back('1');
for(auto &i:adj[n]) if(i != p) {
buildTree(i, n);
}
tree.push_back('0');
}
}
void Init(int N, std::vector<int> U, std::vector<int> V) {
For(i, 0, N - 1) adj[i].clear();
For(i, 0, N - 2) {
adj[U[i]].eb(V[i]);
adj[V[i]].eb(U[i]);
}
cnt = 0;
tree = "";
buildTree(0, 0);
}
std::string SendA(std::string S) {
return tree;
}
#include "Benjamin.h"
#include <string>
#include <vector>
#include <cassert>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
using namespace std;
namespace {
int x, y;
int idx;
string tree;
const int MAXN = 10010;
int d[MAXN];
int p[MAXN];
int cnt;
void buildTree(int dep, int par) {
assert(dep < MAXN);
int n = cnt; cnt++;
d[n] = dep;
p[n] = par;
while(tree[idx] == '1') {
idx++;
buildTree(dep + 1, n);
}
idx++;
}
int getDist(int a, int b) {
int ans = 0;
if(d[a] < d[b]) swap(a, b);
while(d[a] > d[b]) {
a = p[a]; ans++;
}
while(a != b) {
a = p[a]; b = p[b];
ans += 2;
}
return ans;
}
}
std::string SendB(int N, int X, int Y) {
x = X; y = Y;
return "00000111110000011111";
}
int Answer(std::string T) {
tree = T; idx = 1;
cnt = 0;
buildTree(1, 0);
return getDist(x, y);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |