#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 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];
int ans1=INF;
for (int i = 0; i < set2.size(); ++i)
{
ans1=min(ans1,max(dab1[i],sal-dab1[i]));
}
return ans+ans1+L;
}
//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:74:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < set1.size(); ++i)
~~^~~~~~~~~~~~~
dreaming.cpp:81:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < set2.size(); ++i)
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
18800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
18800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
18800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
7416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
18800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
18800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |