Submission #382163

# Submission time Handle Problem Language Result Execution time Memory
382163 2021-03-26T15:42:07 Z MohamedAhmed04 Cheap flights (LMIO18_pigus_skrydziai) C++14
53 / 100
322 ms 48492 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 5e5 + 10 ;

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

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

long long ans = 0ll ;

void dfs(int node , long long x , long long y)
{
	ans = max(ans , x + y) ;
	vis[node] = mark[node] = 1 ;
	long long sum = 0 ;
	for(auto &child : adj[node])
	{
		int to = child.first ;
		sum += child.second ;
		if(vis[to])
		{
			if(mark[to] && dep[to] == dep[node] - 2)
				ans = max(ans , x + y + child.second) ;
			continue ;
		}
		dep[to] = dep[node] + 1 ;
		dfs(to , y , 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 ;
		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 9 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 10 ms 12140 KB Output is correct
6 Correct 14 ms 12524 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 9 ms 12140 KB Output is correct
13 Correct 9 ms 12140 KB Output is correct
14 Correct 9 ms 12140 KB Output is correct
15 Correct 8 ms 12140 KB Output is correct
16 Correct 9 ms 12140 KB Output is correct
17 Correct 9 ms 12140 KB Output is correct
18 Correct 9 ms 12140 KB Output is correct
19 Correct 9 ms 12140 KB Output is correct
20 Correct 9 ms 12140 KB Output is correct
21 Correct 9 ms 12140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12140 KB Output is correct
2 Correct 9 ms 12140 KB Output is correct
3 Correct 9 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 10 ms 12140 KB Output is correct
6 Correct 14 ms 12524 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 9 ms 12140 KB Output is correct
13 Correct 9 ms 12140 KB Output is correct
14 Correct 9 ms 12140 KB Output is correct
15 Correct 8 ms 12140 KB Output is correct
16 Correct 9 ms 12140 KB Output is correct
17 Correct 9 ms 12140 KB Output is correct
18 Correct 9 ms 12140 KB Output is correct
19 Correct 9 ms 12140 KB Output is correct
20 Correct 9 ms 12140 KB Output is correct
21 Correct 9 ms 12140 KB Output is correct
22 Correct 185 ms 23672 KB Output is correct
23 Correct 169 ms 20332 KB Output is correct
24 Correct 18 ms 12780 KB Output is correct
25 Correct 11 ms 12396 KB Output is correct
26 Correct 10 ms 12396 KB Output is correct
27 Correct 9 ms 12140 KB Output is correct
28 Correct 75 ms 16620 KB Output is correct
29 Correct 31 ms 14060 KB Output is correct
30 Correct 47 ms 14444 KB Output is correct
31 Correct 9 ms 12140 KB Output is correct
32 Correct 8 ms 12140 KB Output is correct
33 Correct 169 ms 22312 KB Output is correct
34 Correct 118 ms 21740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 24940 KB Output is correct
2 Correct 239 ms 25068 KB Output is correct
3 Correct 58 ms 16364 KB Output is correct
4 Correct 141 ms 21692 KB Output is correct
5 Correct 289 ms 31596 KB Output is correct
6 Correct 36 ms 14188 KB Output is correct
7 Correct 114 ms 31084 KB Output is correct
8 Correct 117 ms 24940 KB Output is correct
9 Correct 13 ms 15468 KB Output is correct
10 Correct 37 ms 14188 KB Output is correct
11 Correct 91 ms 21084 KB Output is correct
12 Correct 64 ms 16236 KB Output is correct
13 Correct 10 ms 12140 KB Output is correct
14 Correct 45 ms 14572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 24940 KB Output is correct
2 Correct 239 ms 25068 KB Output is correct
3 Correct 58 ms 16364 KB Output is correct
4 Correct 141 ms 21692 KB Output is correct
5 Correct 289 ms 31596 KB Output is correct
6 Correct 36 ms 14188 KB Output is correct
7 Correct 114 ms 31084 KB Output is correct
8 Correct 117 ms 24940 KB Output is correct
9 Correct 13 ms 15468 KB Output is correct
10 Correct 37 ms 14188 KB Output is correct
11 Correct 91 ms 21084 KB Output is correct
12 Correct 64 ms 16236 KB Output is correct
13 Correct 10 ms 12140 KB Output is correct
14 Correct 45 ms 14572 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 9 ms 12140 KB Output is correct
17 Correct 9 ms 12140 KB Output is correct
18 Correct 8 ms 12140 KB Output is correct
19 Correct 10 ms 12140 KB Output is correct
20 Correct 14 ms 12524 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 9 ms 12140 KB Output is correct
27 Correct 9 ms 12140 KB Output is correct
28 Correct 9 ms 12140 KB Output is correct
29 Correct 8 ms 12140 KB Output is correct
30 Correct 9 ms 12140 KB Output is correct
31 Correct 9 ms 12140 KB Output is correct
32 Correct 9 ms 12140 KB Output is correct
33 Correct 9 ms 12140 KB Output is correct
34 Correct 9 ms 12140 KB Output is correct
35 Correct 9 ms 12140 KB Output is correct
36 Correct 185 ms 23672 KB Output is correct
37 Correct 169 ms 20332 KB Output is correct
38 Correct 18 ms 12780 KB Output is correct
39 Correct 11 ms 12396 KB Output is correct
40 Correct 10 ms 12396 KB Output is correct
41 Correct 9 ms 12140 KB Output is correct
42 Correct 75 ms 16620 KB Output is correct
43 Correct 31 ms 14060 KB Output is correct
44 Correct 47 ms 14444 KB Output is correct
45 Correct 9 ms 12140 KB Output is correct
46 Correct 8 ms 12140 KB Output is correct
47 Correct 169 ms 22312 KB Output is correct
48 Correct 118 ms 21740 KB Output is correct
49 Correct 108 ms 18136 KB Output is correct
50 Correct 82 ms 16492 KB Output is correct
51 Correct 105 ms 19296 KB Output is correct
52 Correct 127 ms 18128 KB Output is correct
53 Correct 60 ms 17504 KB Output is correct
54 Correct 141 ms 21484 KB Output is correct
55 Correct 322 ms 48492 KB Output is correct
56 Correct 178 ms 36460 KB Output is correct
57 Correct 169 ms 28380 KB Output is correct
58 Correct 75 ms 16596 KB Output is correct
59 Correct 167 ms 23788 KB Output is correct
60 Incorrect 126 ms 19412 KB Output isn't correct
61 Halted 0 ms 0 KB -