Skip to content

Instantly share code, notes, and snippets.

@ammarfaizi2
Created December 10, 2022 03:16
Show Gist options
  • Save ammarfaizi2/d3778a499173dc9b9f74b41095ef04b8 to your computer and use it in GitHub Desktop.
Save ammarfaizi2/d3778a499173dc9b9f74b41095ef04b8 to your computer and use it in GitHub Desktop.
#include <queue>
#include <stack>
#include <cstdio>
#include <cerrno>
#include <vector>
#include <cstring>
#include <list>
enum QueryType {
QUERY_TYPE_KABUR = 0,
QUERY_TYPE_SIMULASI = 1,
QUERY_TYPE_SUPER = 2,
};
class Query {
public:
enum QueryType type;
};
class QueryKabur: public Query {
public:
int F, E;
// Constructor.
inline QueryKabur(void)
{
type = QUERY_TYPE_KABUR;
}
};
class QuerySimulasi: public Query {
public:
int K;
std::vector<int> arr;
// Constructor.
inline QuerySimulasi(void)
{
type = QUERY_TYPE_SIMULASI;
}
};
class QuerySuper: public Query {
public:
int V1, V2, V3;
// Constructor.
inline QuerySuper(void)
{
type = QUERY_TYPE_SUPER;
}
};
class Route {
public:
int A, B, L, S;
/*
* Constructor.
*/
inline Route(int A_, int B_, int L_, int S_)
{
A = A_;
B = B_;
L = L_;
S = S_;
}
};
class Dressrosa {
public:
int N, M;
std::vector<class Route> routes;
int P;
std::vector<int> kurcaci;
int Q;
std::vector<class Query *> queries;
bool GetInput(void);
bool EvaluateQueries(void);
// Destructor.
~Dressrosa(void);
private:
bool GetQuery(void);
bool GetQueryKabur(void);
bool GetQuerySimulasi(void);
bool GetQuerySuper(void);
bool EvaluateQuery(Query *q);
bool EvaluateQueryKabur(QueryKabur *q);
bool EvaluateQuerySimulasi(QuerySimulasi *q);
};
inline bool Dressrosa::GetInput(void)
{
int i;
/*
* Baris pertama berisi dua buah bilangan
* bulat 𝑁 dan 𝑀 yang dipisahkan dengan
* spasi yang menyatakan banyaknya pos
* dan terowongan.
*/
if (scanf("%d %d", &N, &M) != 2)
return false;
/*
* 𝑀 baris selanjutnya terdiri atas empat
* bilangan bulat 𝐴𝑖, 𝐡𝑖, 𝐿𝑖, dan 𝑆𝑖 yang
* dipisahkan dengan spasi yang menyatakan
* bahwa pos peristirahatan 𝐴𝑖 dan 𝐡𝑖
* dihubungkan oleh terowongan yang
* memiliki panjang 𝐿𝑖 dan berukuran 𝑆𝑖.
*/
for (i = 0; i < M; i++) {
int A, B, L, S;
if (scanf("%d %d %d %d", &A, &B, &L, &S) != 4)
return false;
routes.push_back(Route(A, B, L, S));
}
/*
* Baris berikutnya berisi sebuah bilangan
* bulat 𝑃 yang menyatakan banyaknya
* kurcaci yang ada di dalam keseluruhan
* sistem terowongan.
*/
if (scanf("%d", &P) != 1)
return false;
/*
* 𝑃 baris berikutnya adalah sebuah bilangan
* bulat 𝑅𝑖 yaitu nomor dari pos yang berisi
* kurcaci.
*/
for (i = 0; i < P; i++) {
int R;
if (scanf("%d", &R) != 1)
return false;
kurcaci.push_back(R);
}
/*
* Baris selanjutnya berisi sebuah bilangan
* bulat 𝑄, yaitu banyak query yang akan
* dijalankan.
*/
if (scanf("%d", &Q) != 1)
return false;
/*
* 𝑄 baris berikutnya berisi query sesuai
* dengan penjelasan sebelumnya.
*/
for (i = 0; i < Q; i++) {
if (!GetQuery())
return false;
}
return true;
}
inline bool Dressrosa::GetQuery(void)
{
char buf[32];
if (scanf("%s", buf) != 1)
return false;
if (!strcmp(buf, "KABUR"))
return GetQueryKabur();
if (!strcmp(buf, "SIMULASI"))
return GetQuerySimulasi();
if (!strcmp(buf, "SUPER"))
return GetQuerySuper();
return false;
}
inline bool Dressrosa::GetQueryKabur(void)
{
QueryKabur *tmp;
int F, E;
if (scanf("%d %d", &F, &E) != 2)
return false;
tmp = new QueryKabur;
tmp->F = F;
tmp->E = E;
queries.push_back(tmp);
return true;
}
inline bool Dressrosa::GetQuerySimulasi(void)
{
QuerySimulasi *tmp;
int K;
int V;
if (scanf("%d", &K) != 1)
return false;
tmp = new QuerySimulasi;
while (K--) {
if (scanf("%d", &V) != 1) {
delete tmp;
return false;
}
tmp->arr.push_back(V);
}
queries.push_back(tmp);
return true;
}
inline bool Dressrosa::GetQuerySuper(void)
{
QuerySuper *tmp;
int V1, V2, V3;
if (scanf("%d %d %d", &V1, &V2, &V3))
return false;
tmp = new QuerySuper;
tmp->V1 = V1;
tmp->V2 = V2;
tmp->V3 = V3;
queries.push_back(tmp);
return true;
}
inline bool Dressrosa::EvaluateQueries(void)
{
size_t len = queries.size();
size_t i;
for (i = 0; i < len; i++) {
if (!EvaluateQuery(queries[i]))
return false;
}
return true;
}
inline bool Dressrosa::EvaluateQuery(Query *q)
{
switch (q->type) {
case QUERY_TYPE_KABUR:
return EvaluateQueryKabur(static_cast<QueryKabur *>(q));
case QUERY_TYPE_SIMULASI:
return EvaluateQuerySimulasi(static_cast<QuerySimulasi *>(q));
case QUERY_TYPE_SUPER:
return false;
}
return false;
}
class Graph {
int V;
std::list<int> *adj;
void printAllPathsUtil(int, int, bool[], int[], int&);
};
inline bool Dressrosa::EvaluateQueryKabur(QueryKabur *q)
{
return true;
}
inline int Dressrosa::FindShortestPath(int src, int dst)
{
}
inline bool Dressrosa::EvaluateQuerySimulasi(QuerySimulasi *q)
{
size_t n_kurcaci = kurcaci.size();
size_t K = static_cast<size_t>(q->K);
size_t i;
size_t j;
int min = -1;
// for (i = 0; i < K; i++) {
// int max;
// int tmp;
// max = FindShortestPath(kurcaci[0], q->arr[i]);
// for (j = 1; j < n_kurcaci; j++) {
// tmp = FindShortestPath(kurcaci[0], q->arr[i]);
// if (max < tmp)
// max = tmp;
// }
// }
}
/*
* Destructor. Don't leak memory :)
*/
inline Dressrosa::~Dressrosa(void)
{
size_t len = queries.size();
size_t i;
for (i = 0; i < len; i++)
delete queries[i];
}
int main(void)
{
Dressrosa d;
if (!d.GetInput())
return EINVAL;
if (!d.EvaluateQueries())
return EINVAL;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment