Skip to content

Commit

Permalink
njkjd
Browse files Browse the repository at this point in the history
  • Loading branch information
ArmykOliva committed Feb 20, 2022
1 parent 5291751 commit a21efb0
Show file tree
Hide file tree
Showing 9 changed files with 41,285 additions and 125 deletions.
6 changes: 5 additions & 1 deletion 12 krmeni/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"files.associations": {
"vector": "cpp",
"xhash": "cpp",
"unordered_map": "cpp"
"unordered_map": "cpp",
"iostream": "cpp",
"ostream": "cpp",
"list": "cpp",
"xstring": "cpp"
}
}
119 changes: 0 additions & 119 deletions 12 krmeni/bfs.cpp

This file was deleted.

Binary file removed 12 krmeni/bfs.exe
Binary file not shown.
Binary file added 12 krmeni/main
Binary file not shown.
76 changes: 71 additions & 5 deletions 12 krmeni/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#include <vector>
#include <string>
#include <unordered_map>
#include <list>
using namespace std;

class Mesto {
unsigned int id;
public:
unsigned int id;
unsigned int cena_do_ceska;
bool visited = false;
vector<Mesto*> vyjezdy;
unordered_map<unsigned int,Mesto*> vyjezdy_map;
Mesto(unsigned int id) {
Expand Down Expand Up @@ -42,10 +45,32 @@ vector<unsigned int> fiks_parser() {
return input;
}

void dfs_set_ceny(Mesto* mesto_start) {
list<Mesto*> queue;
mesto_start->visited = true; // cesko
mesto_start->cena_do_ceska = 0;
queue.push_back(mesto_start);

while (!queue.empty()) {
Mesto* front_mesto = queue.front();
//cout << "id: " << front_mesto->id << " cost:" << front_mesto->cena_do_ceska << endl;
queue.pop_front();

for (Mesto* mesto_adj : front_mesto->vyjezdy) {
if (mesto_adj->visited == false) {
mesto_adj->visited = true;
mesto_adj->cena_do_ceska = front_mesto->cena_do_ceska + 1;
queue.push_back(mesto_adj);
}
}
}
}

int main() {
vector<unsigned int> in = fiks_parser();
unsigned int N = in[0];
unsigned int Q = in[1];
unsigned int city_count = 0;
unordered_map<unsigned int,Mesto*> mesta_map;

//load mesta_map a vyjezdy
Expand All @@ -60,6 +85,7 @@ int main() {
Mesto *mesto = new Mesto(from);
mesta_map[from] = mesto;
srch_from = mesta_map.find(from);
city_count ++;
}

//create second city
Expand All @@ -68,6 +94,7 @@ int main() {
Mesto *mesto = new Mesto(to);
mesta_map[to] = mesto;
srch_to = mesta_map.find(to);
city_count++;
}

//spojit mesta_map pokud tam jeste neni ulozeno
Expand All @@ -83,13 +110,52 @@ int main() {
}
}

//
///cena do ceska bfs algoritmem
dfs_set_ceny(mesta_map[1]);


//iterovat dny
for (unsigned int i = 0; i < Q; i++) {
in = fiks_parser();
unsigned int K = in[0];
for (unsigned int Ki = 0; Ki < K; Ki++) {
unsigned int from_mesto_id = in[Ki+1];
auto from_mesto = mesta_map[from_mesto_id];
//prvni algo jestli K=1
if (K == 1) {
unsigned int from_mesto_id = in[1];
Mesto* from_mesto = mesta_map[from_mesto_id];
cout << from_mesto->cena_do_ceska << endl;
}
//druhy algo jestli K>1
else {
//cena do ceska
unsigned celkova_cena_do_ceska = 0;
for (unsigned int Ki = 0; Ki < K; Ki++) {
celkova_cena_do_ceska += mesta_map[in[Ki+1]]->cena_do_ceska;
}

//dfs
vector<unsigned int> ceny;
for (unsigned int Ki = 0; Ki < K; Ki++) {
unsigned int celkova_cena = 0;

//set every city to visited = false
for (auto& mesto : mesta_map) {
mesto.second->visited = false;
}

//dfs
dfs_set_ceny(mesta_map[in[Ki+1]]);

celkova_cena = mesta_map[1]->cena_do_ceska;

ceny.push_back(celkova_cena);
}


cout << celkova_cena_do_ceska;
for (unsigned int cena : ceny) {
cout << " " << cena;
}
cout << endl;
}
}
}
Binary file modified 12 krmeni/main.exe
Binary file not shown.
Loading

0 comments on commit a21efb0

Please sign in to comment.