#include <bits/stdc++.h>
#include "dreaming.h"
#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define ull unsigned long long
#define pqueue priority_queue
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element
const double eps = 0.00000001;
const int NMAX = 2000010;
const ll inf = LLONG_MAX/3;
const ll modi = 998244353;
int D, maks, mx;
vector<pii>al[NMAX];
int visited[NMAX], vv[NMAX];
int maksd,poc;
vector<int>vis,nes;
set<int>vektor;
void izr() {
for (auto u : nes) {
maks = min(maks, max(u,D-u));
}
}
void dfs1(int node, int dist = 0) {
if (visited[node]) {
return;
}
vv[node] = 1;
vis.pb(node);
visited[node] =1;
if ( dist > maksd ) {
maksd = dist;
poc = node;
}
for (auto u : al[node] ) {
dfs1(u.fi, u.se + dist);
}
}
void dfs2(int node, int dist = 0) {
if (visited[node]||maks!= INT_MAX) {
return;
}
vis.pb(node);
visited[node] =1;
nes.pb(dist);
if ( dist == maksd ) {
izr();
return;
}
if ( dist > maksd ) {
maksd = dist;
poc = node;
}
for (auto u : al[node] ) {
dfs2(u.fi, u.se + dist);
}
nes.erase(nes.end()-1);
}
void clrvis() {
for (auto u : vis) {
visited[u] = 0;
}
vis.clear();
}
int travelTime(int n,int m,int l,int A[],int B[],int T[]) {
for (int i = 0 ; i < m; i++) {
al[A[i]].pb({B[i],T[i]});
al[B[i]].pb({A[i],T[i]});
}
vector<int>r;
for (int i = 0 ; i < n ; i++ ) {
if (!vv[i]) {
maksd = -1;
dfs1(i);
clrvis();
maksd = -1;
dfs1(poc);
clrvis();
maks = INT_MAX;
D = maksd;
dfs2(poc);
clrvis();
nes.clear();
r.pb(maks);
}
}
//for (auto u : r) cout << u << ' ';
sort(all(r));
vector<int>t1,t2;
for (int i = 0 ; i < r.size() ; i++) {
if ( i%2 == 0 ) {
t1.pb(r[i]);
}
else {
t2.pb(r[i]);
}
}
reverse(all(t2));
for (auto u : t2) t1.pb(u);
for (auto u : t1) cout << u << ' ';
int res = 0;
int tren = INT_MAX/4;
for (int i = 0 ; i < t1.size(); i++ ) {
res = max(res, t1[i] + l*i - tren);
tren = min(tren, -t1[i] + l*i);
}
return res;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:121:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
121 | for (int i = 0 ; i < r.size() ; i++) {
| ~~^~~~~~~~~~
dreaming.cpp:135:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for (int i = 0 ; i < t1.size(); i++ ) {
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
57620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
57620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
51508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
47172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
57620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |