#pragma GCC optimize("O3,unroll-loops")
#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vii;
#define cont(x) for(auto el:x) {cout<<el<<' ';} cout<<endl;
#define endl '\n'
#define contp(x) for(auto el:x) {cout<<el.fi<<'-'<<el.se<<' ';} cout<<endl;
#define pb push_back
#define sp <<' '<<
#define DEBUG(x) {cout<<(#x) sp x<<endl;}
const int MAXN=1e5+5;
const int INF=1e9;
int n,m,k;
vii adj[MAXN];
//her node için min 3 yolu tut, nereden geldiğiyle birlikte
//yol[i]={j,k} --> k'dan i'ye shortest path=j
multiset<pii> yol[MAXN];
bool vis[MAXN];
bool cikis[MAXN];
int dist[MAXN];
int p[MAXN];
int cev;
void gez(){
set<pii> s;
FORE(i,2,n+1) dist[i]=INF;
dist[1]=0;
s.insert({0,1});
while(!s.empty()){
auto el=*s.begin();
s.erase(*s.begin());
int dd=el.fi;
int nd=el.se;
//cout<<endl;
//cout<<"node" sp nd<<endl;
//cout<<"mesafe" sp dd<<endl;
vis[nd]=true;
int mn=yol[nd].begin()->fi;
int ind=yol[nd].begin()->se;
if(ind==p[nd]){
auto it=yol[nd].begin();
it++;
mn=it->fi;
ind=it->se;
}
//DEBUG(mn);
//DEBUG(ind);
for(auto ell:adj[nd]){
int kom=ell.fi;
int cost=ell.se;
if(kom==ind) continue;
if(kom==p[nd]) continue;
if(vis[kom]) continue;
p[kom]=nd;
dist[kom]=dd+cost;
s.insert({dist[kom],kom});
}
}
}
void dij(int bas){
yol[bas].clear();
yol[bas].insert({0,bas});
yol[bas].insert({0,bas});
yol[bas].insert({0,bas});
multiset<pii> s;
s.insert({0,bas});
while(!s.empty()){
auto el=*s.begin();
s.erase(*s.begin());
int dd=el.fi;
int nd=el.se;
for(auto ell:adj[nd]){
int kom=ell.fi;
int cost=ell.se;
yol[kom].insert({dd+cost,nd});
s.insert({dd+cost,kom});
if(yol[kom].size()>3){
pii son=*yol[kom].rbegin();
yol[kom].erase(yol[kom].find(son));
if(s.find({son.fi,kom})!=s.end()) s.erase(s.find({son.fi,kom}));
}
}
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n=N;
m=M;
k=K;
FOR(i,m){
int bir=R[i][0];
int iki=R[i][1];
bir++;iki++;
adj[bir].pb({iki,L[i]});
adj[iki].pb({bir,L[i]});
}
FOR(i,k){
P[i]++;
cikis[P[i]]=true;
}
FORE(i,1,n+1){
if(cikis[i]){
dij(i);
}
}
gez();
cev=INF;
//cout<<endl;
FORE(i,1,n+1){
//cout<<"i" sp i sp dist[i]<<endl;
if(cikis[i]){
cev=min(dist[i],cev);
}
}
return cev;
}
Compilation message
crocodile.cpp: In function 'void gez()':
crocodile.cpp:61:13: warning: variable 'mn' set but not used [-Wunused-but-set-variable]
61 | int mn=yol[nd].begin()->fi;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
10576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |