Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2024.Q2:
- #include <bits/stdc++.h>
- typedef int_fast64_t lli;
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- lli a, n, m;
- cin >> a >> n >> m;
- map<string, map<string, lli> > mp1;
- map<string, map<string, lli> > mp2;
- for(lli i = 0; i < n; i++)
- {
- lli w;
- string s1, s2;
- cin >> s1 >> s2 >> w;
- mp1[s1][s2] = w+1;
- }
- mp2 = mp1;
- for(lli i = 0; i < m; i++)
- {
- lli w;
- string s1, s2;
- cin >> s1 >> s2 >> w;
- mp2[s1][s2] = w+1;
- }
- lli ans = 0;
- for(auto x : mp1)
- {
- for(auto y : x.second)
- {
- lli cost = y.second - 1;
- lli mn = 1e10;
- for(auto xx : mp2[x.first])
- {
- if(xx.first == y.first)
- {
- mn = min(mn, xx.second - 1);
- }
- else if(mp2[xx.first][y.first] != 0)
- {
- mn = min(mn, xx.second + mp2[xx.first][y.first] - 2);
- }
- }
- //cout << mn << endl;
- ans += cost-mn;
- }
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment