#include "dreaming.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<ull> vull;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
vi groups;
vector<vpi> paths;
vi costs;
void dfs(int pos,int head,int cost,vi visited){
groups[pos] = min(groups[pos],head);
for(auto a:paths[pos]){
if(visited[a.F])continue;
visited[a.F] = 1;
// cout << head << " " << pos << " " << a.F << " " << costs[head] << " " << cost+a.S << endl;
costs[head] = max(costs[head],cost+a.S);
dfs(a.F,head,cost+a.S,visited);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
if(N==1)return 0;
groups = vi(N);
costs = vi(N,0);
paths = vector<vpi>(N);
FOR(i,0,N)groups[i] = i;
FOR(i,0,M){
paths[A[i]].pb({B[i],T[i]});
paths[B[i]].pb({A[i],T[i]});
}
FOR(i,0,N){
vi visited(N,0);
visited[i] = 1;
dfs(i,i,0,visited);
visited.clear();
// FOR(i,0,N){
// cout << setw(2) << i << " ";
// }cout << endl;
// FOR(i,0,N){
// cout << setw(2) << groups[i] << " ";
// }cout << endl;
// FOR(i,0,N){
// cout << setw(2) << costs[i] << " ";
// }cout << endl;
// cout << endl;
}
// FOR(i,0,N){
// cout << setw(2) << i << " ";
// }cout << endl;
// FOR(i,0,N){
// cout << setw(2) << groups[i] << " ";
// }cout << endl;
// FOR(i,0,N){
// cout << setw(2) << costs[i] << " ";
// }cout << endl;
// cout << endl;
vull head(N,1e18);
vi used(N,0);
vi ans;
FOR(i,0,N){
used[groups[i]] = 1;
head[groups[i]] = min(head[groups[i]],(ull)costs[i]);
}
FOR(i,0,N){
if(used[i]){
ans.pb(head[i]);
// cout << i << " -> " << head[i] << endl;
}
}
sort(ans.rbegin(),ans.rend());
return ans[0]+max(ans[1],ans[2]+L)+L;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
48 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
48 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1059 ms |
7020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
48 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |