답안 #362489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362489 2021-02-03T11:29:16 Z _martynas Cheap flights (LMIO18_pigus_skrydziai) C++11
100 / 100
1620 ms 89304 KB
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using ll = long long;
using pii = pair<int, int>;
const int MAX_N = 3e5+5;
const int MAX_M = 5e5+5;
#define PB push_back
#define F first
#define S second

int n, m;
vector<pii> Adj[MAX_N];
map<pii, int> M;
ll Star[MAX_N];
pii MaxWeight[MAX_N][2];

int main()
{
    //freopen("lmio_2018_3e2_menesinis_bilietas_vyr.in", "r", stdin);
    //freopen("lmio_2018_3e2_menesinis_bilietas_vyr.out", "w", stdout);

    scanf("%d%d", &n, &m);

    for(int i = 0; i < m; i++)
    {
        int a, b, w;
        scanf("%d%d%d", &a, &b, &w);
        a--;
        b--;
        Adj[a].PB({b, w});
        Adj[b].PB({a, w});
        Star[a] += w;
        Star[b] += w;
        M[{a, b}] = w;
        M[{b, a}] = w;
    }

    ll ans = 0;

    for(int i = 0; i < n; i++)
    {
        ans = max(ans, Star[i]);
        MaxWeight[i][0] = MaxWeight[i][1] = {-1, 0};
        for(pii e : Adj[i])
        {
            if(MaxWeight[i][0].S < e.S)
            {
                MaxWeight[i][0] = e;
                if(MaxWeight[i][0].S > MaxWeight[i][1].S)
                    swap(MaxWeight[i][0], MaxWeight[i][1]);
            }
        }

        if(MaxWeight[i][0].F != -1)
        {
            auto it = M.find({MaxWeight[i][0].F, MaxWeight[i][1].F});
            if(it != M.end())
                ans = max(ans, (ll)MaxWeight[i][0].S + MaxWeight[i][1].S + it->second);
        }
    }

    printf("%lld", ans);

    return 0;
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |         scanf("%d%d%d", &a, &b, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 6 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 23 ms 10604 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7420 KB Output is correct
11 Correct 6 ms 7532 KB Output is correct
12 Correct 6 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 6 ms 7404 KB Output is correct
18 Correct 7 ms 7532 KB Output is correct
19 Correct 7 ms 7668 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 6 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 23 ms 10604 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7420 KB Output is correct
11 Correct 6 ms 7532 KB Output is correct
12 Correct 6 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 6 ms 7404 KB Output is correct
18 Correct 7 ms 7532 KB Output is correct
19 Correct 7 ms 7668 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
22 Correct 1620 ms 89304 KB Output is correct
23 Correct 607 ms 86764 KB Output is correct
24 Correct 29 ms 10732 KB Output is correct
25 Correct 12 ms 8428 KB Output is correct
26 Correct 12 ms 8428 KB Output is correct
27 Correct 8 ms 7916 KB Output is correct
28 Correct 570 ms 40172 KB Output is correct
29 Correct 190 ms 20332 KB Output is correct
30 Correct 293 ms 27372 KB Output is correct
31 Correct 6 ms 7532 KB Output is correct
32 Correct 6 ms 7532 KB Output is correct
33 Correct 667 ms 87084 KB Output is correct
34 Correct 561 ms 78444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 44780 KB Output is correct
2 Correct 775 ms 65900 KB Output is correct
3 Correct 209 ms 26732 KB Output is correct
4 Correct 454 ms 45676 KB Output is correct
5 Correct 1183 ms 64236 KB Output is correct
6 Correct 129 ms 26220 KB Output is correct
7 Correct 272 ms 57580 KB Output is correct
8 Correct 344 ms 65900 KB Output is correct
9 Correct 11 ms 14572 KB Output is correct
10 Correct 133 ms 26476 KB Output is correct
11 Correct 324 ms 58588 KB Output is correct
12 Correct 332 ms 45472 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 198 ms 23276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 44780 KB Output is correct
2 Correct 775 ms 65900 KB Output is correct
3 Correct 209 ms 26732 KB Output is correct
4 Correct 454 ms 45676 KB Output is correct
5 Correct 1183 ms 64236 KB Output is correct
6 Correct 129 ms 26220 KB Output is correct
7 Correct 272 ms 57580 KB Output is correct
8 Correct 344 ms 65900 KB Output is correct
9 Correct 11 ms 14572 KB Output is correct
10 Correct 133 ms 26476 KB Output is correct
11 Correct 324 ms 58588 KB Output is correct
12 Correct 332 ms 45472 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 198 ms 23276 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 5 ms 7404 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 6 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 23 ms 10604 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7420 KB Output is correct
25 Correct 6 ms 7532 KB Output is correct
26 Correct 6 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 5 ms 7404 KB Output is correct
30 Correct 5 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 7 ms 7532 KB Output is correct
33 Correct 7 ms 7668 KB Output is correct
34 Correct 5 ms 7424 KB Output is correct
35 Correct 5 ms 7424 KB Output is correct
36 Correct 1620 ms 89304 KB Output is correct
37 Correct 607 ms 86764 KB Output is correct
38 Correct 29 ms 10732 KB Output is correct
39 Correct 12 ms 8428 KB Output is correct
40 Correct 12 ms 8428 KB Output is correct
41 Correct 8 ms 7916 KB Output is correct
42 Correct 570 ms 40172 KB Output is correct
43 Correct 190 ms 20332 KB Output is correct
44 Correct 293 ms 27372 KB Output is correct
45 Correct 6 ms 7532 KB Output is correct
46 Correct 6 ms 7532 KB Output is correct
47 Correct 667 ms 87084 KB Output is correct
48 Correct 561 ms 78444 KB Output is correct
49 Correct 567 ms 42836 KB Output is correct
50 Correct 559 ms 40764 KB Output is correct
51 Correct 587 ms 48096 KB Output is correct
52 Correct 826 ms 54860 KB Output is correct
53 Correct 200 ms 28768 KB Output is correct
54 Correct 902 ms 58860 KB Output is correct
55 Correct 754 ms 68460 KB Output is correct
56 Correct 485 ms 47900 KB Output is correct
57 Correct 651 ms 58364 KB Output is correct
58 Correct 355 ms 33492 KB Output is correct
59 Correct 963 ms 58020 KB Output is correct
60 Correct 848 ms 55868 KB Output is correct
61 Correct 880 ms 53484 KB Output is correct