#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
int main() {
char p, q;
int s, t, k, n; cin >> k >> n;
ll ans = 0;
unordered_map<int,int> bruh;
unordered_map<int,int> sus;
vector<int> bridgeplaces;
vector<pair<int, int>> housework;
if (k == 2) {
return 0;
}
ll ahead = 0;
for (int i=0;i<n;i++) {
cin >> p >> s >> q >> t;
if (t > s) {
swap(t, s);
}
if (p == q) {
ans += abs(s - t);
continue;
}
ahead++;
housework.push_back(make_pair(t, s));
if (bruh.find(s) == bruh.end()) {
bruh[s] = 1;
if (sus.find(s) == sus.end()) {
bridgeplaces.push_back(s);
}
} else {
bruh[s]++;
}
if (sus.find(t) == sus.end()) {
sus[t] = 1;
if (bruh.find(t) == bruh.end()) {
bridgeplaces.push_back(t);
}
} else {
sus[t]++;
}
}
sort(bridgeplaces.begin(), bridgeplaces.end());
for (pair<int,int> i: housework) {
ans += i.first + i.second + 1;
}
ll curans = ans;
ll prev = 0;
ll visitednum = 0;
for (int i=0;i<bridgeplaces.size();i++) {
curans += 2 * (bridgeplaces[i] - prev) * (visitednum - ahead);
//cout << visitednum << ' ' << ahead << ' ' << bridgeplaces[i] << ' ' << curans << '\n';
if (bruh.find(bridgeplaces[i]) != bruh.end()) {
visitednum += bruh[bridgeplaces[i]];
}
if (sus.find(bridgeplaces[i]) != sus.end()) {
ahead -= sus[bridgeplaces[i]];
}
ans = min(ans, curans);
prev = bridgeplaces[i];
}
cout << ans;
}
Compilation message
cc1plus: error: '::main' must return 'int'
bridge.cpp: In function 'int main()':
bridge.cpp:56:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i=0;i<bridgeplaces.size();i++) {
| ~^~~~~~~~~~~~~~~~~~~~