답안 #213623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213623 2020-03-26T09:36:42 Z SamAnd Cheap flights (LMIO18_pigus_skrydziai) C++17
100 / 100
1453 ms 85244 KB
#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

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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 12 ms 12032 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 29 ms 14976 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12160 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 12 ms 12160 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Correct 11 ms 12160 KB Output is correct
14 Correct 11 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 11 ms 12032 KB Output is correct
17 Correct 11 ms 12032 KB Output is correct
18 Correct 12 ms 12288 KB Output is correct
19 Correct 14 ms 12416 KB Output is correct
20 Correct 11 ms 12160 KB Output is correct
21 Correct 11 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Correct 11 ms 12032 KB Output is correct
3 Correct 12 ms 12032 KB Output is correct
4 Correct 12 ms 12032 KB Output is correct
5 Correct 11 ms 12032 KB Output is correct
6 Correct 29 ms 14976 KB Output is correct
7 Correct 11 ms 12032 KB Output is correct
8 Correct 11 ms 12032 KB Output is correct
9 Correct 11 ms 12160 KB Output is correct
10 Correct 11 ms 12160 KB Output is correct
11 Correct 12 ms 12160 KB Output is correct
12 Correct 11 ms 12160 KB Output is correct
13 Correct 11 ms 12160 KB Output is correct
14 Correct 11 ms 12032 KB Output is correct
15 Correct 11 ms 12032 KB Output is correct
16 Correct 11 ms 12032 KB Output is correct
17 Correct 11 ms 12032 KB Output is correct
18 Correct 12 ms 12288 KB Output is correct
19 Correct 14 ms 12416 KB Output is correct
20 Correct 11 ms 12160 KB Output is correct
21 Correct 11 ms 12032 KB Output is correct
22 Correct 1453 ms 85244 KB Output is correct
23 Correct 622 ms 82808 KB Output is correct
24 Correct 36 ms 15096 KB Output is correct
25 Correct 18 ms 13056 KB Output is correct
26 Correct 18 ms 13056 KB Output is correct
27 Correct 14 ms 12544 KB Output is correct
28 Correct 504 ms 41212 KB Output is correct
29 Correct 165 ms 23800 KB Output is correct
30 Correct 274 ms 29816 KB Output is correct
31 Correct 12 ms 12160 KB Output is correct
32 Correct 12 ms 12160 KB Output is correct
33 Correct 667 ms 83704 KB Output is correct
34 Correct 554 ms 78072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 42488 KB Output is correct
2 Correct 738 ms 63480 KB Output is correct
3 Correct 199 ms 29048 KB Output is correct
4 Correct 426 ms 45560 KB Output is correct
5 Correct 1068 ms 63992 KB Output is correct
6 Correct 129 ms 30968 KB Output is correct
7 Correct 285 ms 56060 KB Output is correct
8 Correct 360 ms 63480 KB Output is correct
9 Correct 14 ms 12288 KB Output is correct
10 Correct 128 ms 31096 KB Output is correct
11 Correct 351 ms 59748 KB Output is correct
12 Correct 280 ms 49916 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 188 ms 27896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 42488 KB Output is correct
2 Correct 738 ms 63480 KB Output is correct
3 Correct 199 ms 29048 KB Output is correct
4 Correct 426 ms 45560 KB Output is correct
5 Correct 1068 ms 63992 KB Output is correct
6 Correct 129 ms 30968 KB Output is correct
7 Correct 285 ms 56060 KB Output is correct
8 Correct 360 ms 63480 KB Output is correct
9 Correct 14 ms 12288 KB Output is correct
10 Correct 128 ms 31096 KB Output is correct
11 Correct 351 ms 59748 KB Output is correct
12 Correct 280 ms 49916 KB Output is correct
13 Correct 11 ms 12032 KB Output is correct
14 Correct 188 ms 27896 KB Output is correct
15 Correct 512 ms 45912 KB Output is correct
16 Correct 474 ms 44920 KB Output is correct
17 Correct 537 ms 50284 KB Output is correct
18 Correct 792 ms 58584 KB Output is correct
19 Correct 222 ms 30316 KB Output is correct
20 Correct 856 ms 63352 KB Output is correct
21 Correct 750 ms 66168 KB Output is correct
22 Correct 469 ms 47864 KB Output is correct
23 Correct 610 ms 57060 KB Output is correct
24 Correct 344 ms 37088 KB Output is correct
25 Correct 898 ms 61688 KB Output is correct
26 Correct 812 ms 59732 KB Output is correct
27 Correct 814 ms 57848 KB Output is correct
28 Correct 12 ms 12032 KB Output is correct
29 Correct 11 ms 12032 KB Output is correct
30 Correct 12 ms 12032 KB Output is correct
31 Correct 12 ms 12032 KB Output is correct
32 Correct 11 ms 12032 KB Output is correct
33 Correct 29 ms 14976 KB Output is correct
34 Correct 11 ms 12032 KB Output is correct
35 Correct 11 ms 12032 KB Output is correct
36 Correct 11 ms 12160 KB Output is correct
37 Correct 11 ms 12160 KB Output is correct
38 Correct 12 ms 12160 KB Output is correct
39 Correct 11 ms 12160 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 11 ms 12032 KB Output is correct
42 Correct 11 ms 12032 KB Output is correct
43 Correct 11 ms 12032 KB Output is correct
44 Correct 11 ms 12032 KB Output is correct
45 Correct 12 ms 12288 KB Output is correct
46 Correct 14 ms 12416 KB Output is correct
47 Correct 11 ms 12160 KB Output is correct
48 Correct 11 ms 12032 KB Output is correct
49 Correct 1453 ms 85244 KB Output is correct
50 Correct 622 ms 82808 KB Output is correct
51 Correct 36 ms 15096 KB Output is correct
52 Correct 18 ms 13056 KB Output is correct
53 Correct 18 ms 13056 KB Output is correct
54 Correct 14 ms 12544 KB Output is correct
55 Correct 504 ms 41212 KB Output is correct
56 Correct 165 ms 23800 KB Output is correct
57 Correct 274 ms 29816 KB Output is correct
58 Correct 12 ms 12160 KB Output is correct
59 Correct 12 ms 12160 KB Output is correct
60 Correct 667 ms 83704 KB Output is correct
61 Correct 554 ms 78072 KB Output is correct