#include<dreaming.h>
#include <bits/stdc++.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;
vector<int> connected;
void dfs(int source, long long int largest){
vis[source] = 1;
mx = max(mx, largest);
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});
// cout << u << ' ' << v << ' ' << c << endl;
}
vector<long long int> paths;
for(int i = 0; i < N; ++i){
if(!vis[i]){
dfs(i, 0);
long long int mn = mx;
mx = 0;
for(int j = 1; j < connected.size(); ++j){
for(auto k : connected)
vis[k] = 0;
dfs1(connected[j], 0);
mn = min(mx, mn);
mx = 0;
}
// cout << mn << '\n';
for(auto k : connected)
vis[k] = 1;
paths.push_back(mn);
connected.clear();
}
}
sort(paths.rbegin(), paths.rend());
return (int) (L + paths[0] + paths[1]);
}
/* int main(){
fast;
int n, m, l;
cin >> n >> m >> l;
int a[m], b[m], t[m];
for(int i = 0; i < m; ++i)
cin >> a[i];
for(int i = 0; i < m; ++i)
cin >> b[i];
for(int i = 0; i < m; ++i)
cin >> t[i];
cout << travelTime(n, m, l, a, b, t) << '\n';
return 0;
}
*/
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:44:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int j = 1; j < connected.size(); ++j){
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1075 ms |
34152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1075 ms |
34152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1075 ms |
34152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
27248 KB |
Output is correct |
2 |
Incorrect |
53 ms |
27364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1075 ms |
34152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1075 ms |
34152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |