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 "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<pair<int, int>>> adj;
vector<int> U, V;
set<vector<int>> sv;
vector<int> res;
void check_tree(vector<int> edges, set<int> nodes)
{
if (nodes.size() == N)
{
sort(edges.begin(), edges.end());
if (sv.count(edges))
return;
sv.insert(edges);
int common = count_common_roads(edges);
if (common == N - 1)
res = edges;
return;
}
for (auto node : nodes)
{
for (auto edge : adj[node])
{
if (nodes.count(edge.first))
continue;
nodes.insert(edge.first);
edges.push_back(edge.second);
check_tree(edges, nodes);
nodes.erase(edge.first);
edges.pop_back();
}
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v)
{
N = n; M = u.size();;
u = U; v = V;
adj = vector<vector<pair<int, int>>>(N);
sv.clear();
for (int i = 0; i < M; i++)
{
adj[u[i]].push_back({v[i], i});
adj[v[i]].push_back({u[i], i});
}
check_tree({}, {0});
return res;
}
Compilation message (stderr)
simurgh.cpp: In function 'void check_tree(std::vector<int>, std::set<int>)':
simurgh.cpp:15:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
15 | if (nodes.size() == N)
| ~~~~~~~~~~~~~^~~~
# | 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... |