Branch data Line data Source code
1 : : #include <iostream>
2 : : #include <fstream>
3 : : #include <unordered_map>
4 : : #include <unordered_set>
5 : : #include <string>
6 : : using namespace std;
7 : :
8 : 2 : int main() {
9 : 2 : ifstream input("input.txt");
10 [ + + ]: 2 : if (!input) {
11 : 1 : cerr << "Error: Could not open input file.\n";
12 : 1 : return 1;
13 : : }
14 : 1 : unordered_map<string, unordered_set<string>> connections;
15 : :
16 [ + + + - : 3381 : for (string a, b; getline(input, a, '-') && getline(input, b);) {
+ + ]
17 [ + + ]: 3380 : if(a < b) {
18 : 1704 : connections[a].insert(b);
19 : : } else {
20 : 1676 : connections[b].insert(a);
21 : : }
22 : 1 : }
23 : :
24 : 1 : int count = 0;
25 : :
26 [ + + ]: 506 : for (const auto& [node, neighbors] : connections) {
27 [ + + ]: 3885 : for (const auto& neighbor : neighbors) {
28 [ + + ]: 16894 : for (const auto& common : connections[neighbor]) {
29 [ + + + + : 13514 : if (connections[node].contains(common) && (node[0] == 't' || neighbor[0] == 't' || common[0] == 't')) {
+ + + + +
+ ]
30 : 1154 : ++count;
31 : : }
32 : : }
33 : : }
34 : : }
35 : :
36 : 1 : cout << count << endl;
37 [ + + ]: 3 : }
|