#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MOD1 1000000009
#define sqr(x) sqr((x)*(x))
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef BE_DEBUG
#define debug(...) cerr << "\033[1;31m(" << #__VA_ARGS__ << "):\033[0m", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int BB = 100005;
int par[BB];
vector<pair<int,int> > edge[BB];
bool visited[BB];
vector<int> v;
int a[BB],b[BB]; //
int tmp;
multiset<int> s;
multiset<int> :: iterator it;
vector<int> gold;
int mn;
void dfs(int node) {
//cout << node << ' ';
visited[node] = 1;
v.pb(node);
for(auto x: edge[node]) {
if(visited[x.ff] == 1) continue;
a[x.ff] = x.ss;
dfs(x.ff);
b[node] = max(b[node], a[x.ff]);
if(node == tmp) {
s.insert(-(b[x.ff] + x.ss));
}
}
a[node] += b[node];
}
void go(int node, int cost) {
visited[node] = 1;
if(s.size() != 0) {
it = s.begin();
mn = min(mn, max(b[node],cost - *it));
}
else {
mn = min(mn, max(b[node], cost));
}
for(auto x: edge[node]) {
if(visited[x.ff] == 1) continue;
if(tmp == node) {
it = s.lower_bound(-a[x.ff]);
s.erase(it);
}
go(x.ff, x.ss + cost);
s.insert(-a[x.ff]);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i = 0; i < N; i ++) {
par[i] = i;
}
for(int i = 0; i < M; i ++) {
edge[A[i]].pb({B[i], T[i]});
edge[B[i]].pb({A[i], T[i]});
}
for(int i = 0; i < N; i ++) {
if(visited[i] == 1) continue;
s.clear();
v.clear();
tmp = i;
dfs(i);
for(auto x: v) {
visited[x] = 0;
}
mn = 1e9;
go(i,0);
gold.pb(mn);
}
sort(gold.begin(), gold.end());
if(gold.size() == 1) {
return gold[gold.size() - 1];
}
int q = gold.size() - 1;
if(gold.size() == 2) {
return gold[q] + gold[q - 1] + L;
}
return max(gold[q] + gold[q - 1] + L, gold[q - 1] + gold[q - 2] + L + L);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
17052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
17052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
6476 KB |
Output is correct |
2 |
Correct |
20 ms |
6480 KB |
Output is correct |
3 |
Correct |
22 ms |
6468 KB |
Output is correct |
4 |
Correct |
27 ms |
6452 KB |
Output is correct |
5 |
Correct |
20 ms |
6524 KB |
Output is correct |
6 |
Correct |
21 ms |
6952 KB |
Output is correct |
7 |
Correct |
25 ms |
6704 KB |
Output is correct |
8 |
Correct |
23 ms |
6392 KB |
Output is correct |
9 |
Correct |
20 ms |
6448 KB |
Output is correct |
10 |
Correct |
21 ms |
6608 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
6 ms |
4432 KB |
Output is correct |
13 |
Correct |
6 ms |
4480 KB |
Output is correct |
14 |
Correct |
6 ms |
4432 KB |
Output is correct |
15 |
Correct |
7 ms |
4432 KB |
Output is correct |
16 |
Correct |
6 ms |
4432 KB |
Output is correct |
17 |
Correct |
5 ms |
4176 KB |
Output is correct |
18 |
Correct |
8 ms |
4432 KB |
Output is correct |
19 |
Correct |
8 ms |
4432 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
5 ms |
4432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
17052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |