forked from adnanaziz/EPIJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_circuit_wirable.cc
56 lines (47 loc) · 1.43 KB
/
is_circuit_wirable.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdexcept>
#include <vector>
#include "test_framework/generic_test.h"
#include "test_framework/serialization_traits.h"
#include "test_framework/timed_executor.h"
using std::vector;
struct GraphVertex {
int d = -1;
vector<GraphVertex*> edges;
};
bool IsAnyPlacementFeasible(vector<GraphVertex>* graph) {
// TODO - you fill in here.
return true;
}
struct Edge {
int from;
int to;
};
namespace test_framework {
template <>
struct SerializationTrait<Edge> : UserSerTrait<Edge, int, int> {};
} // namespace test_framework
bool IsAnyPlacementFeasibleWrapper(TimedExecutor& executor, int k,
const vector<Edge>& edges) {
vector<GraphVertex> graph;
if (k <= 0) {
throw std::runtime_error("Invalid k value");
}
graph.reserve(k);
for (int i = 0; i < k; i++) {
graph.push_back(GraphVertex{});
}
for (auto& e : edges) {
if (e.from < 0 || e.from >= k || e.to < 0 || e.to >= k) {
throw std::runtime_error("Invalid vertex index");
}
graph[e.from].edges.push_back(&graph[e.to]);
}
return executor.Run([&] { return IsAnyPlacementFeasible(&graph); });
}
int main(int argc, char* argv[]) {
std::vector<std::string> args{argv + 1, argv + argc};
std::vector<std::string> param_names{"executor", "k", "edges"};
return GenericTestMain(
args, "is_circuit_wirable.cc", "is_circuit_wirable.tsv",
&IsAnyPlacementFeasibleWrapper, DefaultComparator{}, param_names);
}