이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ve vector
#define vi vector<int>
#define vii vector<ii>
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
#define INF 1e9+7
#define pb push_back
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
const int MOD = 1e9+7;
const int nax = 1e5+5;
#include "fun.h"
int mx = 0, node = 0;
vi adj[nax];
bool vis[nax];
void farthest(int u, int p, int dep){
if(mx < dep) node = u, mx = dep;
for(auto x : adj[u]){
if(x == p || vis[x] == 1) continue;
farthest(x,u,dep+1);
}
}
std::vector<int> createFunTour(int N, int Q) {
vi res;
for(int i = 0; i < N; i++){
for(int j = i+1; j < N; j++){
if(hoursRequired(i,j) == 1) {
adj[i].pb(j);
adj[j].pb(i);
}
}
}
int root = 0;
for (int i = 0; i < N; ++i)
{
if(adj[i].size() == 1) root = i;
}
res.pb(root);
vis[root] = 1;
for (int i = 0; i < N-1; ++i)
{
node = 0, mx = 0;
farthest(root, root, 0);
vis[node] = 1;
res.pb(node);
root = node;
}
return res;
}
# | 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... |