Submission #382167

# Submission time Handle Problem Language Result Execution time Memory
382167 2021-03-26T15:48:47 Z MohamedAhmed04 Cheap flights (LMIO18_pigus_skrydziai) C++14
53 / 100
274 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)
{
	vis[node] = mark[node] = 1 ;
	long long sum = 0 ;
	for(auto &child : adj[node])
	{
		if(!mark[child.first] || dep[child.first] != dep[node] - 1)
			ans = max(ans , y + child.second) ;
		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 8 ms 12140 KB Output is correct
2 Correct 8 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 9 ms 12140 KB Output is correct
6 Correct 13 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 9 ms 12268 KB Output is correct
11 Correct 8 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 8 ms 12140 KB Output is correct
15 Correct 8 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 8 ms 12140 KB Output is correct
19 Correct 10 ms 12140 KB Output is correct
20 Correct 8 ms 12140 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 8 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 9 ms 12140 KB Output is correct
6 Correct 13 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 9 ms 12268 KB Output is correct
11 Correct 8 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 8 ms 12140 KB Output is correct
15 Correct 8 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 8 ms 12140 KB Output is correct
19 Correct 10 ms 12140 KB Output is correct
20 Correct 8 ms 12140 KB Output is correct
21 Correct 8 ms 12140 KB Output is correct
22 Correct 191 ms 23660 KB Output is correct
23 Correct 162 ms 20332 KB Output is correct
24 Correct 15 ms 12800 KB Output is correct
25 Correct 10 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 72 ms 16620 KB Output is correct
29 Correct 34 ms 14060 KB Output is correct
30 Correct 51 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 154 ms 22380 KB Output is correct
34 Correct 123 ms 21740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 25016 KB Output is correct
2 Correct 225 ms 25068 KB Output is correct
3 Correct 56 ms 16364 KB Output is correct
4 Correct 139 ms 21664 KB Output is correct
5 Correct 264 ms 31724 KB Output is correct
6 Correct 37 ms 14188 KB Output is correct
7 Correct 108 ms 31084 KB Output is correct
8 Correct 118 ms 24940 KB Output is correct
9 Correct 13 ms 15468 KB Output is correct
10 Correct 38 ms 14188 KB Output is correct
11 Correct 92 ms 21084 KB Output is correct
12 Correct 66 ms 16236 KB Output is correct
13 Correct 8 ms 12140 KB Output is correct
14 Correct 37 ms 14700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 25016 KB Output is correct
2 Correct 225 ms 25068 KB Output is correct
3 Correct 56 ms 16364 KB Output is correct
4 Correct 139 ms 21664 KB Output is correct
5 Correct 264 ms 31724 KB Output is correct
6 Correct 37 ms 14188 KB Output is correct
7 Correct 108 ms 31084 KB Output is correct
8 Correct 118 ms 24940 KB Output is correct
9 Correct 13 ms 15468 KB Output is correct
10 Correct 38 ms 14188 KB Output is correct
11 Correct 92 ms 21084 KB Output is correct
12 Correct 66 ms 16236 KB Output is correct
13 Correct 8 ms 12140 KB Output is correct
14 Correct 37 ms 14700 KB Output is correct
15 Correct 8 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 8 ms 12140 KB Output is correct
19 Correct 9 ms 12140 KB Output is correct
20 Correct 13 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 9 ms 12268 KB Output is correct
25 Correct 8 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 8 ms 12140 KB Output is correct
29 Correct 8 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 8 ms 12140 KB Output is correct
33 Correct 10 ms 12140 KB Output is correct
34 Correct 8 ms 12140 KB Output is correct
35 Correct 8 ms 12140 KB Output is correct
36 Correct 191 ms 23660 KB Output is correct
37 Correct 162 ms 20332 KB Output is correct
38 Correct 15 ms 12800 KB Output is correct
39 Correct 10 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 72 ms 16620 KB Output is correct
43 Correct 34 ms 14060 KB Output is correct
44 Correct 51 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 154 ms 22380 KB Output is correct
48 Correct 123 ms 21740 KB Output is correct
49 Correct 97 ms 18120 KB Output is correct
50 Correct 87 ms 16492 KB Output is correct
51 Correct 101 ms 19296 KB Output is correct
52 Correct 118 ms 18128 KB Output is correct
53 Correct 57 ms 17504 KB Output is correct
54 Correct 115 ms 21484 KB Output is correct
55 Correct 274 ms 48492 KB Output is correct
56 Correct 168 ms 36332 KB Output is correct
57 Correct 164 ms 28380 KB Output is correct
58 Correct 64 ms 16596 KB Output is correct
59 Correct 174 ms 23916 KB Output is correct
60 Incorrect 115 ms 19404 KB Output isn't correct
61 Halted 0 ms 0 KB -