#include <bits/stdc++.h>
#include<dreaming.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
vector<pair<long long int, long long int> > graph[N];
bool vis[N];
long long int mx = 0, node1;
vector<int> disconnected, connected;
void dfs(int source, long long int largest){
vis[source] = 1;
if(largest >= mx){
mx = largest;
node1 = source;
}
connected.push_back(source);
for(auto k : graph[source])
if(!vis[k.first])
dfs(k.first, largest + k.second);
}
void dfs1(int source, long long int largest){
vis[source] = 1;
mx = max(mx, largest);
for(auto k : graph[source])
if(!vis[k.first])
dfs1(k.first, largest + k.second);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
for(int i = 0; i < M; ++i){
long long int u = A[i], v = B[i], c = T[i];
graph[u].push_back({v, c});
graph[v].push_back({u, c});
}
for(int i = 0; i < N; ++i){
if(!vis[i]){
dfs1(i, 0);
disconnected.push_back(i);
}
}
for(int i = 0; i < N; ++i)
vis[i] = 0;
int u = disconnected[0];
for(int i = 1; i < disconnected.size(); ++i){
int v = disconnected[i];
graph[u].push_back({v, L});
graph[v].push_back({u, L});
}
mx = 0;
for(int i = 0; i < N; ++i)
vis[i] = 0;
dfs(0, 0);
for(int i = 0; i < N; ++i)
vis[i] = 0;
dfs(node1, 0);
return mx;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i = 1; i < disconnected.size(); ++i){
| ~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
35808 KB |
Output is correct |
2 |
Correct |
79 ms |
36832 KB |
Output is correct |
3 |
Correct |
51 ms |
32484 KB |
Output is correct |
4 |
Correct |
22 ms |
25836 KB |
Output is correct |
5 |
Correct |
21 ms |
25068 KB |
Output is correct |
6 |
Correct |
29 ms |
26856 KB |
Output is correct |
7 |
Incorrect |
17 ms |
23916 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
35808 KB |
Output is correct |
2 |
Correct |
79 ms |
36832 KB |
Output is correct |
3 |
Correct |
51 ms |
32484 KB |
Output is correct |
4 |
Correct |
22 ms |
25836 KB |
Output is correct |
5 |
Correct |
21 ms |
25068 KB |
Output is correct |
6 |
Correct |
29 ms |
26856 KB |
Output is correct |
7 |
Incorrect |
17 ms |
23916 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
35808 KB |
Output is correct |
2 |
Correct |
79 ms |
36832 KB |
Output is correct |
3 |
Correct |
51 ms |
32484 KB |
Output is correct |
4 |
Correct |
22 ms |
25836 KB |
Output is correct |
5 |
Correct |
21 ms |
25068 KB |
Output is correct |
6 |
Correct |
29 ms |
26856 KB |
Output is correct |
7 |
Incorrect |
17 ms |
23916 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
30436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
35808 KB |
Output is correct |
2 |
Correct |
79 ms |
36832 KB |
Output is correct |
3 |
Correct |
51 ms |
32484 KB |
Output is correct |
4 |
Correct |
22 ms |
25836 KB |
Output is correct |
5 |
Correct |
21 ms |
25068 KB |
Output is correct |
6 |
Correct |
29 ms |
26856 KB |
Output is correct |
7 |
Incorrect |
17 ms |
23916 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
35808 KB |
Output is correct |
2 |
Correct |
79 ms |
36832 KB |
Output is correct |
3 |
Correct |
51 ms |
32484 KB |
Output is correct |
4 |
Correct |
22 ms |
25836 KB |
Output is correct |
5 |
Correct |
21 ms |
25068 KB |
Output is correct |
6 |
Correct |
29 ms |
26856 KB |
Output is correct |
7 |
Incorrect |
17 ms |
23916 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |