Submission #461326

# Submission time Handle Problem Language Result Execution time Memory
461326 2021-08-09T19:08:25 Z idas Cheap flights (LMIO18_pigus_skrydziai) C++11
100 / 100
1736 ms 101224 KB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

void setIO (string s)
 {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N=3e5+10, M=5e5+10;

int n, m;
ll cn[N], ans;
map<pii, ll> con;
set<pii, greater<pii>> ad[N];

int main()
{
    setIO();
    cin >> n >> m;
    FOR(i, 0, m)
    {
        int a, b; ll c;
        cin >> a >> b >> c;
        cn[a-1]+=c;
        cn[b-1]+=c;
        ad[a-1].insert({c, b-1});
        ad[b-1].insert({c, a-1});
        con[{min(a-1, b-1), max(a-1, b-1)}]=c;
    }

    FOR(i, 0, n) ans=max(ans, cn[i]);

    FOR(i, 0, n)
    {
        int in=2;
        int k=-1, b=-1;
        for(auto[x, y] : ad[i]){
            if(in){
                if(in==2){
                    k=y;
                }
                else{
                    b=y;
                }
                in--;
            }
            else break;
        }

        ll val=con[{min(i, k), max(i, k)}]+
        con[{min(i, b), max(i, b)}]+
        con[{min(k, b), max(k, b)}];
        ans=max(ans, val);
    }

    cout << ans;
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:64:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |         for(auto[x, y] : ad[i]){
      |                 ^
pigus_skrydziai.cpp: In function 'void setIO(std::string)':
pigus_skrydziai.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14284 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14400 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14408 KB Output is correct
6 Correct 28 ms 17504 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 8 ms 14412 KB Output is correct
9 Correct 8 ms 14412 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 8 ms 14412 KB Output is correct
12 Correct 8 ms 14444 KB Output is correct
13 Correct 8 ms 14408 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14364 KB Output is correct
16 Correct 9 ms 14540 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 10 ms 14540 KB Output is correct
19 Correct 10 ms 14716 KB Output is correct
20 Correct 8 ms 14412 KB Output is correct
21 Correct 8 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14284 KB Output is correct
2 Correct 8 ms 14284 KB Output is correct
3 Correct 8 ms 14400 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14408 KB Output is correct
6 Correct 28 ms 17504 KB Output is correct
7 Correct 8 ms 14412 KB Output is correct
8 Correct 8 ms 14412 KB Output is correct
9 Correct 8 ms 14412 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 8 ms 14412 KB Output is correct
12 Correct 8 ms 14444 KB Output is correct
13 Correct 8 ms 14408 KB Output is correct
14 Correct 8 ms 14412 KB Output is correct
15 Correct 8 ms 14364 KB Output is correct
16 Correct 9 ms 14540 KB Output is correct
17 Correct 8 ms 14412 KB Output is correct
18 Correct 10 ms 14540 KB Output is correct
19 Correct 10 ms 14716 KB Output is correct
20 Correct 8 ms 14412 KB Output is correct
21 Correct 8 ms 14412 KB Output is correct
22 Correct 1736 ms 97864 KB Output is correct
23 Correct 983 ms 101224 KB Output is correct
24 Correct 32 ms 17860 KB Output is correct
25 Correct 14 ms 15436 KB Output is correct
26 Correct 14 ms 15404 KB Output is correct
27 Correct 11 ms 14808 KB Output is correct
28 Correct 525 ms 49204 KB Output is correct
29 Correct 156 ms 27972 KB Output is correct
30 Correct 309 ms 36072 KB Output is correct
31 Correct 9 ms 14540 KB Output is correct
32 Correct 9 ms 14540 KB Output is correct
33 Correct 943 ms 99312 KB Output is correct
34 Correct 546 ms 90052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 58972 KB Output is correct
2 Correct 666 ms 82512 KB Output is correct
3 Correct 184 ms 37060 KB Output is correct
4 Correct 401 ms 60312 KB Output is correct
5 Correct 1036 ms 77156 KB Output is correct
6 Correct 136 ms 33904 KB Output is correct
7 Correct 272 ms 67048 KB Output is correct
8 Correct 291 ms 63848 KB Output is correct
9 Correct 117 ms 35540 KB Output is correct
10 Correct 135 ms 33860 KB Output is correct
11 Correct 357 ms 62560 KB Output is correct
12 Correct 283 ms 53540 KB Output is correct
13 Correct 8 ms 14412 KB Output is correct
14 Correct 211 ms 30028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 58972 KB Output is correct
2 Correct 666 ms 82512 KB Output is correct
3 Correct 184 ms 37060 KB Output is correct
4 Correct 401 ms 60312 KB Output is correct
5 Correct 1036 ms 77156 KB Output is correct
6 Correct 136 ms 33904 KB Output is correct
7 Correct 272 ms 67048 KB Output is correct
8 Correct 291 ms 63848 KB Output is correct
9 Correct 117 ms 35540 KB Output is correct
10 Correct 135 ms 33860 KB Output is correct
11 Correct 357 ms 62560 KB Output is correct
12 Correct 283 ms 53540 KB Output is correct
13 Correct 8 ms 14412 KB Output is correct
14 Correct 211 ms 30028 KB Output is correct
15 Correct 10 ms 14284 KB Output is correct
16 Correct 8 ms 14284 KB Output is correct
17 Correct 8 ms 14400 KB Output is correct
18 Correct 8 ms 14412 KB Output is correct
19 Correct 8 ms 14408 KB Output is correct
20 Correct 28 ms 17504 KB Output is correct
21 Correct 8 ms 14412 KB Output is correct
22 Correct 8 ms 14412 KB Output is correct
23 Correct 8 ms 14412 KB Output is correct
24 Correct 8 ms 14412 KB Output is correct
25 Correct 8 ms 14412 KB Output is correct
26 Correct 8 ms 14444 KB Output is correct
27 Correct 8 ms 14408 KB Output is correct
28 Correct 8 ms 14412 KB Output is correct
29 Correct 8 ms 14364 KB Output is correct
30 Correct 9 ms 14540 KB Output is correct
31 Correct 8 ms 14412 KB Output is correct
32 Correct 10 ms 14540 KB Output is correct
33 Correct 10 ms 14716 KB Output is correct
34 Correct 8 ms 14412 KB Output is correct
35 Correct 8 ms 14412 KB Output is correct
36 Correct 1736 ms 97864 KB Output is correct
37 Correct 983 ms 101224 KB Output is correct
38 Correct 32 ms 17860 KB Output is correct
39 Correct 14 ms 15436 KB Output is correct
40 Correct 14 ms 15404 KB Output is correct
41 Correct 11 ms 14808 KB Output is correct
42 Correct 525 ms 49204 KB Output is correct
43 Correct 156 ms 27972 KB Output is correct
44 Correct 309 ms 36072 KB Output is correct
45 Correct 9 ms 14540 KB Output is correct
46 Correct 9 ms 14540 KB Output is correct
47 Correct 943 ms 99312 KB Output is correct
48 Correct 546 ms 90052 KB Output is correct
49 Correct 515 ms 48736 KB Output is correct
50 Correct 522 ms 48812 KB Output is correct
51 Correct 655 ms 60680 KB Output is correct
52 Correct 861 ms 64132 KB Output is correct
53 Correct 325 ms 41984 KB Output is correct
54 Correct 801 ms 66504 KB Output is correct
55 Correct 667 ms 89652 KB Output is correct
56 Correct 421 ms 64196 KB Output is correct
57 Correct 661 ms 75420 KB Output is correct
58 Correct 295 ms 39680 KB Output is correct
59 Correct 799 ms 68204 KB Output is correct
60 Correct 858 ms 63332 KB Output is correct
61 Correct 834 ms 63244 KB Output is correct