Submission #213583

#TimeUsernameProblemLanguageResultExecution timeMemory
213583SamAndCheap flights (LMIO18_pigus_skrydziai)C++17
12 / 100
3103 ms82168 KiB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 5003;

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(y, z));
        a[y].push_back(m_p(x, z));
        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].second;
        }
        ans = max(ans, yans);
    }
    for (int x = 1; x <= n; ++x)
    {
        for (int i = 0; i < a[x].size(); ++i)
        {
            for (int j = i + 1; j < a[x].size(); ++j)
            {
                int h1 = a[x][i].first;
                int h2 = a[x][j].first;
                if (mp.find(m_p(h1, h2)) != mp.end())
                    ans = max(ans, a[x][i].second + 0LL + a[x][j].second + mp[m_p(h1, h2)]);
            }
        }
    }
    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:34:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
pigus_skrydziai.cpp:36:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = i + 1; j < a[x].size(); ++j)
                                 ~~^~~~~~~~~~~~~
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...