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 "fun.h"
#include <bits/stdc++.h>
using namespace std;
int dist[100005], bad[100005];
vector<int> adj[100005], ans;
queue<pair<int, int> > q;
vector<int> createFunTour(int n, int Q)
{
for (int i=0; i<n; i++)
{
for (int j=i+1; j<n; j++)
{
if (hoursRequired(i, j)==1)
{
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
int cur=0;
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
dist[j]=1e9;
dist[cur]=0;
q.push({cur, -1});
while (!q.empty())
{
int u=q.front().first, p=q.front().second;
q.pop();
for (int v:adj[u])
{
if (v==p || bad[v])
continue;
dist[v]=dist[u]+1;
q.push({v, u});
}
}
int ind, mx=-1;
for (int j=0; j<n; j++)
{
if (!bad[j] && mx<dist[j])
{
mx=dist[j];
ind=j;
}
}
ans.push_back(ind);
bad[ind]=1;
cur=ind;
}
return ans;
}
# | 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... |