Submission #795929

# Submission time Handle Problem Language Result Execution time Memory
795929 2023-07-27T22:51:45 Z vjudge1 Cheap flights (LMIO18_pigus_skrydziai) C++17
100 / 100
676 ms 77840 KB
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

#define mp make_pair
#define pb push_back
#define pii pair<int, int>

const int maxN = 1e6 + 10;

vector<pii> v[maxN], v1[maxN];
long long cnt[maxN], cnt1[maxN];
int n, m;

int main() {

    cin >> n >> m;
	

    for (int i = 1; i<=m; i++) {
    	int x, y, z;
    	scanf("%d%d%d", &x, &y, &z);
    	cnt[x]+=z;
    	cnt[y]+=z;
    	v[x].pb(mp(y, z));
    	v[y].pb(mp(x, z));
    }


    long long ans = 0;

    for (int i = 1; i<=n; i++) {
    	ans = max(ans, cnt[i]);
    }


    for (int i = 1; i<= n; i++) {
    	for (auto j: v[i]) {
    		if (j.first > i) continue;
    		int x = i;
    		int y = j.first;
    		int z = j.second;
    		if (v[x].size() > v[y].size()) swap(x, y);
    		v1[x].pb(mp(y, z));
    	}
    }

    for (int i = 1; i<=n; i++) {
    	for (auto j: v1[i]) {

    		for (auto k: v1[i]) {
    			cnt1[k.first] = k.second;
    		}

    		for (auto k: v1[j.first]) {
    			cnt1[k.first]+=k.second;
    			ans = max(ans, j.second + cnt1[k.first]);
    			cnt1[k.first] = 0;
    		}

    		for (auto k: v1[i]) {
    			cnt1[k.first] = 0;
    		}

    	}
    }

    cout << ans << endl;

	return 0;
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:26:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |      scanf("%d%d%d", &x, &y, &z);
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47204 KB Output is correct
2 Correct 24 ms 47200 KB Output is correct
3 Correct 22 ms 47256 KB Output is correct
4 Correct 23 ms 47228 KB Output is correct
5 Correct 23 ms 47188 KB Output is correct
6 Correct 31 ms 47852 KB Output is correct
7 Correct 22 ms 47220 KB Output is correct
8 Correct 22 ms 47260 KB Output is correct
9 Correct 23 ms 47276 KB Output is correct
10 Correct 23 ms 47284 KB Output is correct
11 Correct 23 ms 47232 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 24 ms 47256 KB Output is correct
14 Correct 24 ms 47188 KB Output is correct
15 Correct 23 ms 47188 KB Output is correct
16 Correct 27 ms 47188 KB Output is correct
17 Correct 23 ms 47204 KB Output is correct
18 Correct 23 ms 47224 KB Output is correct
19 Correct 24 ms 47252 KB Output is correct
20 Correct 23 ms 47244 KB Output is correct
21 Correct 22 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47204 KB Output is correct
2 Correct 24 ms 47200 KB Output is correct
3 Correct 22 ms 47256 KB Output is correct
4 Correct 23 ms 47228 KB Output is correct
5 Correct 23 ms 47188 KB Output is correct
6 Correct 31 ms 47852 KB Output is correct
7 Correct 22 ms 47220 KB Output is correct
8 Correct 22 ms 47260 KB Output is correct
9 Correct 23 ms 47276 KB Output is correct
10 Correct 23 ms 47284 KB Output is correct
11 Correct 23 ms 47232 KB Output is correct
12 Correct 24 ms 47188 KB Output is correct
13 Correct 24 ms 47256 KB Output is correct
14 Correct 24 ms 47188 KB Output is correct
15 Correct 23 ms 47188 KB Output is correct
16 Correct 27 ms 47188 KB Output is correct
17 Correct 23 ms 47204 KB Output is correct
18 Correct 23 ms 47224 KB Output is correct
19 Correct 24 ms 47252 KB Output is correct
20 Correct 23 ms 47244 KB Output is correct
21 Correct 22 ms 47188 KB Output is correct
22 Correct 315 ms 63952 KB Output is correct
23 Correct 676 ms 69260 KB Output is correct
24 Correct 30 ms 48304 KB Output is correct
25 Correct 25 ms 47564 KB Output is correct
26 Correct 25 ms 47496 KB Output is correct
27 Correct 24 ms 47396 KB Output is correct
28 Correct 159 ms 56956 KB Output is correct
29 Correct 83 ms 50944 KB Output is correct
30 Correct 122 ms 52836 KB Output is correct
31 Correct 24 ms 47284 KB Output is correct
32 Correct 24 ms 47296 KB Output is correct
33 Correct 196 ms 70488 KB Output is correct
34 Correct 241 ms 66596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 66028 KB Output is correct
2 Correct 191 ms 68856 KB Output is correct
3 Correct 61 ms 54368 KB Output is correct
4 Correct 120 ms 62908 KB Output is correct
5 Correct 195 ms 65228 KB Output is correct
6 Correct 115 ms 50620 KB Output is correct
7 Correct 114 ms 70184 KB Output is correct
8 Correct 131 ms 72096 KB Output is correct
9 Correct 28 ms 51284 KB Output is correct
10 Correct 116 ms 51836 KB Output is correct
11 Correct 112 ms 63184 KB Output is correct
12 Correct 209 ms 55776 KB Output is correct
13 Correct 24 ms 47180 KB Output is correct
14 Correct 61 ms 51720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 66028 KB Output is correct
2 Correct 191 ms 68856 KB Output is correct
3 Correct 61 ms 54368 KB Output is correct
4 Correct 120 ms 62908 KB Output is correct
5 Correct 195 ms 65228 KB Output is correct
6 Correct 115 ms 50620 KB Output is correct
7 Correct 114 ms 70184 KB Output is correct
8 Correct 131 ms 72096 KB Output is correct
9 Correct 28 ms 51284 KB Output is correct
10 Correct 116 ms 51836 KB Output is correct
11 Correct 112 ms 63184 KB Output is correct
12 Correct 209 ms 55776 KB Output is correct
13 Correct 24 ms 47180 KB Output is correct
14 Correct 61 ms 51720 KB Output is correct
15 Correct 27 ms 47204 KB Output is correct
16 Correct 24 ms 47200 KB Output is correct
17 Correct 22 ms 47256 KB Output is correct
18 Correct 23 ms 47228 KB Output is correct
19 Correct 23 ms 47188 KB Output is correct
20 Correct 31 ms 47852 KB Output is correct
21 Correct 22 ms 47220 KB Output is correct
22 Correct 22 ms 47260 KB Output is correct
23 Correct 23 ms 47276 KB Output is correct
24 Correct 23 ms 47284 KB Output is correct
25 Correct 23 ms 47232 KB Output is correct
26 Correct 24 ms 47188 KB Output is correct
27 Correct 24 ms 47256 KB Output is correct
28 Correct 24 ms 47188 KB Output is correct
29 Correct 23 ms 47188 KB Output is correct
30 Correct 27 ms 47188 KB Output is correct
31 Correct 23 ms 47204 KB Output is correct
32 Correct 23 ms 47224 KB Output is correct
33 Correct 24 ms 47252 KB Output is correct
34 Correct 23 ms 47244 KB Output is correct
35 Correct 22 ms 47188 KB Output is correct
36 Correct 315 ms 63952 KB Output is correct
37 Correct 676 ms 69260 KB Output is correct
38 Correct 30 ms 48304 KB Output is correct
39 Correct 25 ms 47564 KB Output is correct
40 Correct 25 ms 47496 KB Output is correct
41 Correct 24 ms 47396 KB Output is correct
42 Correct 159 ms 56956 KB Output is correct
43 Correct 83 ms 50944 KB Output is correct
44 Correct 122 ms 52836 KB Output is correct
45 Correct 24 ms 47284 KB Output is correct
46 Correct 24 ms 47296 KB Output is correct
47 Correct 196 ms 70488 KB Output is correct
48 Correct 241 ms 66596 KB Output is correct
49 Correct 89 ms 58596 KB Output is correct
50 Correct 95 ms 58020 KB Output is correct
51 Correct 161 ms 62556 KB Output is correct
52 Correct 178 ms 61080 KB Output is correct
53 Correct 76 ms 56964 KB Output is correct
54 Correct 284 ms 65932 KB Output is correct
55 Correct 217 ms 77840 KB Output is correct
56 Correct 116 ms 67356 KB Output is correct
57 Correct 149 ms 71096 KB Output is correct
58 Correct 72 ms 55192 KB Output is correct
59 Correct 148 ms 63884 KB Output is correct
60 Correct 121 ms 61900 KB Output is correct
61 Correct 120 ms 59764 KB Output is correct