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 "bits/stdc++.h"
#include "citymapping.h"
using namespace std;
using ll = long long;
#define eb emplace_back
#define nl endl
void find_roads(int N, int Q, int A[], int B[], int W[]) {
deque<int> path;
vector<int> dist[N];
int p = 1;
for(int i = 2; i <= N; ++i) {
int d = get_distance(1, i);
dist[d].eb(i);
if((int)dist[d].size() == 2) p = d + 1;
}
/* for(int i = 0; i < N; ++i) { */
/* cout << i << ": "; */
/* for(int j : dist[i]) cout << j << ' '; */
/* cout << nl; */
/* } */
path.eb(1);
for(int i = 1; i < p; ++i) {
int a = dist[i][0], b = dist[i][1];
if(get_distance(a, path.back()) == 1) swap(a, b);
path.emplace_front(a); path.eb(b);
}
/* cout << endl; */
/* for(int i : path) cout << i << ' '; */
/* cout << endl; */
int a = dist[p][0];
if(get_distance(a, path.back()) == 1)
for(int i = p; i < N && dist[i].size() != 0; ++i)
path.eb(dist[i][0]);
else
for(int i = p; i < N && dist[i].size() != 0; ++i)
path.emplace_front(dist[i][0]);
for(int i = 0; i < N; ++i) {
A[i] = path[i], B[i] = path[i + 1], W[i] = 1;
/* cout << A[i] << ' ' << B[i] << ' ' << W[i] << endl; */
}
return;
}
# | 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... |