-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.2.cpp
47 lines (45 loc) · 1.06 KB
/
9.2.cpp
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
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <limits>
int main()
{
std::ifstream fin("test.txt");
std::map<std::pair<std::string, std::string>, int> distances;
std::vector<std::string> cities;
std::string to, from, eater;
int distance = 0, max_distance = 0;
int dist;
{
std::set<std::string> temp;
while (fin >> from >> eater >> to >> eater >> dist)
{
distances[std::make_pair(from, to)] = dist;
temp.insert(from);
temp.insert(to);
}
cities.assign(temp.begin(), temp.end());
}
for (const auto & e : distances)
{
distances[std::make_pair(e.first.second, e.first.first)] = e.second;
}
do
{
for (std::size_t i = 0; i < cities.size() - 1; i++)
{
distance += distances[std::make_pair(cities[i], cities[i + 1])];
}
if (distance > max_distance)
{
max_distance = distance;
}
distance = 0;
} while (std::next_permutation(cities.begin(), cities.end()));
std::cout << max_distance;
}