This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;
struct data{
mutable int time,cost;
data(int x,int y):time(x),cost(y){}
bool operator<(const data& A)const{
return time<A.time;
}
};
struct Cont : set<data>{
void add(data A){
if(empty()){
insert(A);
return;
}
iterator pre=upper_bound(A);
if(pre!=begin()){
pre--;
if(pre->cost<=A.cost)return;
if(pre->time==A.time&&pre->cost>A.cost)erase(pre);
}
iterator curr=insert(A).first;
iterator next=curr;
next++;
while(next!=end()&&next->cost>=A.cost)next=erase(next);
}
};
struct P{
int y,t,c;
P(int a,int b,int C){
y=a;
t=b;
c=C;
}
};
vector<bool>vis(2002,false);
vector<Cont> val(2002);
vector<P>adj[2002];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("q.gir","r",stdin);
// freopen("q.cik","w",stdout);
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++){
int x,y,t,c;
cin>>x>>y>>t>>c;
adj[x].pb(P(y,t,c));
adj[y].pb(P(x,t,c));
}
val[1].add(data(0,0));
priority_queue<ii,vector<ii>,greater<ii>> Q;
Q.push({0,1});
while(!Q.empty()){
int x,y,t,c;
x=Q.top().second;
Q.pop();
if(vis[x])continue;
vis[x]=true;
for(int i=0;i<adj[x].size();i++){
y=adj[x][i].y;
t=adj[x][i].t;
c=adj[x][i].c;
if(vis[y])continue;
for(Cont::iterator itr=val[x].begin();itr!=val[x].end();itr++){
val[y].add(data(itr->time+t,itr->cost+c));
Q.push({(itr->time+t)*(itr->cost+c),y});
}
}
}
for(int i=2;i<=n;i++){
if(val[i].empty())cout<<-1<<"\n";
else {
int ans=INF;
for(Cont::iterator itr=val[i].begin();itr!=val[i].end();itr++){
ans=min(ans,itr->time*itr->cost);
}
cout<<ans<<"\n";
}
}
}
Compilation message (stderr)
ceste.cpp: In function 'int32_t main()':
ceste.cpp:68:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[x].size();i++){
~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |