제출 #1139371

#제출 시각아이디문제언어결과실행 시간메모리
1139371seby1305Cheap flights (LMIO18_pigus_skrydziai)C++20
12 / 100
2347 ms327680 KiB
#include <bits/stdc++.h> #define ll long long #define pi pair<int, char> #define pint pair<int, int> #define ff first #define ss second #define pb push_back #define all(v) v.begin(), v.end() #define allsir(v) v+1, v+n+1 #define inf 1e9 using namespace std; const string file = ""; ifstream fin(file+".in"); ofstream fout(file+".out"); const int dim = 500001, mod = 1e9+7; int n, m, i, j; ll gr[dim]; vector<pint> g[dim]; unordered_map<int, ll> ma[dim]; struct muchie { int a, b, c; } lm[dim]; void solve() { cin >> n >> m; int a, b, c; ll profit = 0; for (i = 1; i <= m; i++) { cin >> a >> b >> c; lm[i] = {a, b, c}; gr[a] += c; gr[b] += c; profit = max(profit, gr[a]); profit = max(profit, gr[b]); g[a].pb({b, c}); g[b].pb({a, c}); ma[a][b] = c; ma[b][a] = c; } if (n <= 5000) { for (i = 1; i <= m; i++) { int a = lm[i].a, b = lm[i].b, c = lm[i].c; for (auto x : g[a]) { if (x.ff != b && ma[x.ff][b]) profit = max(profit, (ll)c+x.ss+ma[x.ff][b]); } for (auto x : g[b]) { if (x.ff != a && ma[x.ff][a]) profit = max(profit, (ll)c+x.ss+ma[x.ff][a]); } } } cout << profit; } int main() { int t = 1; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...