#include <bits/stdc++.h>
#include"dreaming.h"
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
vector<int>graph[100001];
map<pair<int,int>,int>gg;
bool vis[100001];
int dab[100001],dab1[100001];
vector<int>set1,set2;
void dfs(int node,int ka)
{
vis[node]=1;
if(!ka)set1.pb(node);
else set2.pb(node);
for(auto it:graph[node])
{
if(!vis[it])dfs(it,ka);
}
}
int travelTime(int N,int M,int L,
int A[],int B[],int T[])
{
int deb=-1,deb1=-1,deb2=-1,deb3=-1;
for (int i = 0; i < M; ++i)
{
graph[A[i]].pb(B[i]);
graph[B[i]].pb(A[i]);
gg[{min(A[i],B[i]),max(A[i],B[i])}]=T[i];
}
for (int i = 0; i < N; ++i)
{
////debugs(i,graph[i].size());
if(graph[i].size()==1 && deb==-1)deb=i;
else if(graph[i].size()==1 && deb1==-1)deb1=i;
else if(graph[i].size()==1 && deb2==-1)deb2=i;
else if(graph[i].size()==1 && deb3==-1)deb3=i;
}
dfs(deb,0);
if(!vis[deb1])dfs(deb1,1);
if(!vis[deb2])dfs(deb2,1);
if(!vis[deb3])dfs(deb3,1);
for (int i = 1; i < set1.size(); ++i)
{
//debug(set1[i]);
dab[i]+=(gg[{min(set1[i-1],set1[i]),max(set1[i-1],set1[i])}]+dab[i-1]);
}
for (int i = 1; i < set2.size(); ++i)
{
//debug(set2[i]);
dab1[i]+=(gg[{min(set2[i-1],set2[i]),max(set2[i-1],set2[i])}]+dab1[i-1]);
}
int sal=dab[set1.size()-1];
int fat=sal;
int ans=INF;
for (int i = 0; i < set1.size(); ++i)
{
//debugs(dab[i],sal-dab[i]);
ans=min(ans,max(dab[i],sal-dab[i]));
}
sal=dab1[set2.size()-1];
//debugs(sal,set2.size());
int ans1=INF;
for (int i = 0; i < set2.size(); ++i)
{
//debugs(dab1[i],sal-dab1[i]);
ans1=min(ans1,max(dab1[i],sal-dab1[i]));
}
//debugs(ans1,ans);
return max(ans+ans1+L,max(sal,fat));
}
//code the AC sol !
// BS/queue/map
Compilation message
dreaming.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("O3")
dreaming.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("unroll-loops")
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:62:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < set1.size(); ++i)
~~^~~~~~~~~~~~~
dreaming.cpp:67:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < set2.size(); ++i)
~~^~~~~~~~~~~~~
dreaming.cpp:75:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < set1.size(); ++i)
~~^~~~~~~~~~~~~
dreaming.cpp:83:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < set2.size(); ++i)
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
17492 KB |
Output is correct |
2 |
Correct |
149 ms |
18752 KB |
Output is correct |
3 |
Correct |
83 ms |
13404 KB |
Output is correct |
4 |
Correct |
19 ms |
5112 KB |
Output is correct |
5 |
Correct |
15 ms |
4216 KB |
Output is correct |
6 |
Correct |
28 ms |
6392 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
57 ms |
9080 KB |
Output is correct |
9 |
Correct |
75 ms |
11124 KB |
Output is correct |
10 |
Correct |
4 ms |
2812 KB |
Output is correct |
11 |
Correct |
126 ms |
14264 KB |
Output is correct |
12 |
Correct |
136 ms |
16368 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
17492 KB |
Output is correct |
2 |
Correct |
149 ms |
18752 KB |
Output is correct |
3 |
Correct |
83 ms |
13404 KB |
Output is correct |
4 |
Correct |
19 ms |
5112 KB |
Output is correct |
5 |
Correct |
15 ms |
4216 KB |
Output is correct |
6 |
Correct |
28 ms |
6392 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
57 ms |
9080 KB |
Output is correct |
9 |
Correct |
75 ms |
11124 KB |
Output is correct |
10 |
Correct |
4 ms |
2812 KB |
Output is correct |
11 |
Correct |
126 ms |
14264 KB |
Output is correct |
12 |
Correct |
136 ms |
16368 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
17492 KB |
Output is correct |
2 |
Correct |
149 ms |
18752 KB |
Output is correct |
3 |
Correct |
83 ms |
13404 KB |
Output is correct |
4 |
Correct |
19 ms |
5112 KB |
Output is correct |
5 |
Correct |
15 ms |
4216 KB |
Output is correct |
6 |
Correct |
28 ms |
6392 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
57 ms |
9080 KB |
Output is correct |
9 |
Correct |
75 ms |
11124 KB |
Output is correct |
10 |
Correct |
4 ms |
2812 KB |
Output is correct |
11 |
Correct |
126 ms |
14264 KB |
Output is correct |
12 |
Correct |
136 ms |
16368 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
7032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
17492 KB |
Output is correct |
2 |
Correct |
149 ms |
18752 KB |
Output is correct |
3 |
Correct |
83 ms |
13404 KB |
Output is correct |
4 |
Correct |
19 ms |
5112 KB |
Output is correct |
5 |
Correct |
15 ms |
4216 KB |
Output is correct |
6 |
Correct |
28 ms |
6392 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
57 ms |
9080 KB |
Output is correct |
9 |
Correct |
75 ms |
11124 KB |
Output is correct |
10 |
Correct |
4 ms |
2812 KB |
Output is correct |
11 |
Correct |
126 ms |
14264 KB |
Output is correct |
12 |
Correct |
136 ms |
16368 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Incorrect |
5 ms |
2808 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
17492 KB |
Output is correct |
2 |
Correct |
149 ms |
18752 KB |
Output is correct |
3 |
Correct |
83 ms |
13404 KB |
Output is correct |
4 |
Correct |
19 ms |
5112 KB |
Output is correct |
5 |
Correct |
15 ms |
4216 KB |
Output is correct |
6 |
Correct |
28 ms |
6392 KB |
Output is correct |
7 |
Correct |
4 ms |
2808 KB |
Output is correct |
8 |
Correct |
57 ms |
9080 KB |
Output is correct |
9 |
Correct |
75 ms |
11124 KB |
Output is correct |
10 |
Correct |
4 ms |
2812 KB |
Output is correct |
11 |
Correct |
126 ms |
14264 KB |
Output is correct |
12 |
Correct |
136 ms |
16368 KB |
Output is correct |
13 |
Correct |
5 ms |
2808 KB |
Output is correct |
14 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |