제출 #1139384

#제출 시각아이디문제언어결과실행 시간메모리
1139384seby1305Cheap flights (LMIO18_pigus_skrydziai)C++20
100 / 100
1161 ms124648 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 = 300001, dim2 = 500001, mod = 1e9+7; int n, m, i, j, viz[dim]; ll gr[dim]; vector<pint> g[dim]; map<int, int> ma[dim]; void dfs(int nod, int prev, ll& profit) { viz[nod] = 1; for (auto x : g[nod]) { if (x.ff != prev && ma[x.ff][prev]) profit = max(profit, (ll)x.ss+ma[nod][prev]+ma[x.ff][prev]); if (!viz[x.ff]) dfs(x.ff, nod, profit); } } void solve() { cin >> n >> m; int a, b, c; ll profit = 0; for (i = 1; i <= m; i++) { cin >> 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; } for (i = 1; i <= n; i++) { if (!viz[i]) dfs(i, 0, profit); } 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...