Submission #382172

# Submission time Handle Problem Language Result Execution time Memory
382172 2021-03-26T15:54:30 Z MohamedAhmed04 Cheap flights (LMIO18_pigus_skrydziai) C++14
100 / 100
1592 ms 94316 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 5e5 + 10 ;

int vis[MAX] , mark[MAX] ;
int n , m ;

vector< vector< pair<int , int> > >adj(MAX) ;

long long ans = 0ll ;

map< pair<int , int> , int>mp ;

void dfs(int node , int par , long long x)
{
	vis[node] = mark[node] = 1 ;
	long long sum = 0 ;
	for(auto &child : adj[node])
	{
		if(child.first != par)
			ans = max(ans , x + child.second) ;
		int to = child.first ;
		sum += child.second ;
		if(vis[to])
		{
			if(mark[to] && mp.find({par , to}) != mp.end())
				ans = max(ans , x + child.second + mp[{par , to}]) ;
			continue ;
		}
		dfs(to , node , child.second) ;
	}
	ans = max(ans , sum) ;
	mark[node] = 0 ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y , z ;
		cin>>x>>y>>z ;
		mp[{x , y}] = mp[{y , x}] = z ;
		adj[x].emplace_back(y , z) ;
		adj[y].emplace_back(x , z) ;
	}
	for(int i = 1 ; i <= n ; ++i)
	{
		if(!vis[i])
			dfs(i , 0 , 0) ;
	}
	return cout<<ans<<"\n" , 0 ;
}		
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 8 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 8 ms 12140 KB Output is correct
6 Correct 27 ms 15084 KB Output is correct
7 Correct 8 ms 12140 KB Output is correct
8 Correct 8 ms 12140 KB Output is correct
9 Correct 8 ms 12140 KB Output is correct
10 Correct 8 ms 12140 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 8 ms 12140 KB Output is correct
13 Correct 8 ms 12140 KB Output is correct
14 Correct 9 ms 12140 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 8 ms 12140 KB Output is correct
17 Correct 8 ms 12140 KB Output is correct
18 Correct 10 ms 12268 KB Output is correct
19 Correct 10 ms 12396 KB Output is correct
20 Correct 10 ms 12288 KB Output is correct
21 Correct 8 ms 12140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 8 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 8 ms 12140 KB Output is correct
6 Correct 27 ms 15084 KB Output is correct
7 Correct 8 ms 12140 KB Output is correct
8 Correct 8 ms 12140 KB Output is correct
9 Correct 8 ms 12140 KB Output is correct
10 Correct 8 ms 12140 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 8 ms 12140 KB Output is correct
13 Correct 8 ms 12140 KB Output is correct
14 Correct 9 ms 12140 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 8 ms 12140 KB Output is correct
17 Correct 8 ms 12140 KB Output is correct
18 Correct 10 ms 12268 KB Output is correct
19 Correct 10 ms 12396 KB Output is correct
20 Correct 10 ms 12288 KB Output is correct
21 Correct 8 ms 12140 KB Output is correct
22 Correct 1592 ms 86124 KB Output is correct
23 Correct 663 ms 82932 KB Output is correct
24 Correct 33 ms 15212 KB Output is correct
25 Correct 15 ms 13164 KB Output is correct
26 Correct 15 ms 13164 KB Output is correct
27 Correct 11 ms 12524 KB Output is correct
28 Correct 475 ms 41452 KB Output is correct
29 Correct 165 ms 23916 KB Output is correct
30 Correct 311 ms 29932 KB Output is correct
31 Correct 9 ms 12268 KB Output is correct
32 Correct 9 ms 12268 KB Output is correct
33 Correct 612 ms 83692 KB Output is correct
34 Correct 546 ms 78060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 42688 KB Output is correct
2 Correct 723 ms 61548 KB Output is correct
3 Correct 190 ms 28524 KB Output is correct
4 Correct 428 ms 45420 KB Output is correct
5 Correct 1122 ms 71660 KB Output is correct
6 Correct 145 ms 29952 KB Output is correct
7 Correct 252 ms 65512 KB Output is correct
8 Correct 293 ms 61528 KB Output is correct
9 Correct 13 ms 14572 KB Output is correct
10 Correct 143 ms 29932 KB Output is correct
11 Correct 309 ms 57948 KB Output is correct
12 Correct 286 ms 47596 KB Output is correct
13 Correct 8 ms 12140 KB Output is correct
14 Correct 207 ms 27244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 42688 KB Output is correct
2 Correct 723 ms 61548 KB Output is correct
3 Correct 190 ms 28524 KB Output is correct
4 Correct 428 ms 45420 KB Output is correct
5 Correct 1122 ms 71660 KB Output is correct
6 Correct 145 ms 29952 KB Output is correct
7 Correct 252 ms 65512 KB Output is correct
8 Correct 293 ms 61528 KB Output is correct
9 Correct 13 ms 14572 KB Output is correct
10 Correct 143 ms 29932 KB Output is correct
11 Correct 309 ms 57948 KB Output is correct
12 Correct 286 ms 47596 KB Output is correct
13 Correct 8 ms 12140 KB Output is correct
14 Correct 207 ms 27244 KB Output is correct
15 Correct 8 ms 12140 KB Output is correct
16 Correct 9 ms 12140 KB Output is correct
17 Correct 8 ms 12140 KB Output is correct
18 Correct 8 ms 12140 KB Output is correct
19 Correct 8 ms 12140 KB Output is correct
20 Correct 27 ms 15084 KB Output is correct
21 Correct 8 ms 12140 KB Output is correct
22 Correct 8 ms 12140 KB Output is correct
23 Correct 8 ms 12140 KB Output is correct
24 Correct 8 ms 12140 KB Output is correct
25 Correct 9 ms 12140 KB Output is correct
26 Correct 8 ms 12140 KB Output is correct
27 Correct 8 ms 12140 KB Output is correct
28 Correct 9 ms 12140 KB Output is correct
29 Correct 9 ms 12140 KB Output is correct
30 Correct 8 ms 12140 KB Output is correct
31 Correct 8 ms 12140 KB Output is correct
32 Correct 10 ms 12268 KB Output is correct
33 Correct 10 ms 12396 KB Output is correct
34 Correct 10 ms 12288 KB Output is correct
35 Correct 8 ms 12140 KB Output is correct
36 Correct 1592 ms 86124 KB Output is correct
37 Correct 663 ms 82932 KB Output is correct
38 Correct 33 ms 15212 KB Output is correct
39 Correct 15 ms 13164 KB Output is correct
40 Correct 15 ms 13164 KB Output is correct
41 Correct 11 ms 12524 KB Output is correct
42 Correct 475 ms 41452 KB Output is correct
43 Correct 165 ms 23916 KB Output is correct
44 Correct 311 ms 29932 KB Output is correct
45 Correct 9 ms 12268 KB Output is correct
46 Correct 9 ms 12268 KB Output is correct
47 Correct 612 ms 83692 KB Output is correct
48 Correct 546 ms 78060 KB Output is correct
49 Correct 499 ms 43976 KB Output is correct
50 Correct 492 ms 41324 KB Output is correct
51 Correct 554 ms 47204 KB Output is correct
52 Correct 754 ms 54348 KB Output is correct
53 Correct 191 ms 29536 KB Output is correct
54 Correct 827 ms 58476 KB Output is correct
55 Correct 756 ms 94316 KB Output is correct
56 Correct 479 ms 66996 KB Output is correct
57 Correct 573 ms 60252 KB Output is correct
58 Correct 331 ms 35924 KB Output is correct
59 Correct 1000 ms 61956 KB Output is correct
60 Correct 761 ms 56712 KB Output is correct
61 Correct 826 ms 57884 KB Output is correct