Submission #213623

#TimeUsernameProblemLanguageResultExecution timeMemory
213623SamAndCheap flights (LMIO18_pigus_skrydziai)C++17
100 / 100
1453 ms85244 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 500005; int n, m; vector<pair<int, int> > a[N]; map<pair<int, int>, int> mp; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { int x, y, z; scanf("%d%d%d", &x, &y, &z); a[x].push_back(m_p(z, y)); a[y].push_back(m_p(z, x)); mp[m_p(x, y)] = z; mp[m_p(y, x)] = z; } long long ans = 0; for (int x = 1; x <= n; ++x) { long long yans = 0; for (int i = 0; i < a[x].size(); ++i) { yans += a[x][i].first; } ans = max(ans, yans); } for (int x = 1; x <= n; ++x) { sort(a[x].begin(), a[x].end()); reverse(a[x].begin(), a[x].end()); if (a[x].size() >= 2 && mp.find(m_p(a[x][0].second, a[x][1].second)) != mp.end()) ans = max(ans, a[x][0].first + 0LL + a[x][1].first + mp[m_p(a[x][0].second, a[x][1].second)]); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:26:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
pigus_skrydziai.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &z);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...