#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010 , MAXT = MAXN * MAXN;
struct edge
{
int to , time , cost ;
edge(int ve , int ti , int co)
{
to = ve ;
time = ti ;
cost = co ;
}
};
vector< vector<edge> >adj(MAXN) ;
long long ans[MAXN] , tillnow[MAXN] ;
int n , m ;
int main()
{
scanf("%d %d" , &n, &m) ;
int a , b , c , d ;
for(int i = 0 ; i < m ; ++i)
{
scanf("%d %d %d %d" , &a , &b , &c , &d) ;
adj[a].push_back(edge(b , c , d)) ;
adj[b].push_back(edge(a , c , d)) ;
}
long long cons = 1e17 ;
for(int i = 1 ; i <= n ; ++i)
ans[i] = cons , tillnow[i] = 1e17;
priority_queue< pair<int , pair<int , int> > , vector< pair<int , pair<int , int> > > , greater< pair<int , pair<int , int> > > >q ;
q.push({0 , {0 , 1}}) ;
while(!q.empty())
{
pair<int , pair<int , int> >p = q.top() ;
q.pop() ;
int node = p.second.second , sumc = p.first , sumt = p.second.first ;
ans[node] = min(ans[node] , (sumt * 1ll) * (sumc * 1ll)) ;
if(sumt > tillnow[node])
continue;
tillnow[node] = sumt ;
for(auto &child : adj[node])
{
int nto = child.to ;
int ntime = child.time + sumt;
int ncost = child.cost + sumc;
if(ntime >= MAXT)
continue ;
q.push({ncost , {ntime , nto}}) ;
}
}
for(int i = 2 ; i <= n ; ++i)
{
if(ans[i] == cons)
ans[i] = -1 ;
printf("%lld\n" , ans[i]);
}
return 0 ;
}
Compilation message
ceste.cpp: In function 'int main()':
ceste.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d" , &n, &m) ;
~~~~~^~~~~~~~~~~~~~~~~~~
ceste.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d" , &a , &b , &c , &d) ;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1276 KB |
Output is correct |
2 |
Correct |
51 ms |
2040 KB |
Output is correct |
3 |
Correct |
64 ms |
2168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
2160 KB |
Output is correct |
2 |
Correct |
480 ms |
12948 KB |
Output is correct |
3 |
Correct |
8 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
984 KB |
Output is correct |
2 |
Correct |
290 ms |
6716 KB |
Output is correct |
3 |
Correct |
13 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
924 KB |
Output is correct |
2 |
Correct |
207 ms |
2304 KB |
Output is correct |
3 |
Correct |
184 ms |
2160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
2172 KB |
Output is correct |
2 |
Correct |
185 ms |
2156 KB |
Output is correct |
3 |
Correct |
268 ms |
2160 KB |
Output is correct |