# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
701758 |
2023-02-22T04:59:07 Z |
tamthegod |
Ceste (COCI17_ceste) |
C++17 |
|
92 ms |
35120 KB |
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2000 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e14;
int n, m;
struct TAdj
{
int v, w, c;
};
vector<TAdj> adj[maxN];
int d[maxN][2005];
struct TPQRect
{
int vertex, time, dlab;
bool operator < (const TPQRect& other) const
{
return other.dlab < dlab;
}
bool Valid() const
{
return d[vertex][time] == dlab;
}
};
void ReadInput()
{
cin >> n >> m;
for(int i=1; i<=m; i++)
{
int u, v, w, c;
cin >> u >> v >> w >> c;
adj[u].pb({v, w, c});
adj[v].pb({u, w, c});
}
}
void Dijkstra()
{
memset(d, 3, sizeof d);
d[1][0] = 0;
priority_queue<TPQRect> pq;
pq.push({1, 0, 0});
while(!pq.empty())
{
TPQRect r = pq.top();
pq.pop();
if(!r.Valid()) continue;
int u = r.vertex, t = r.time;
for(TAdj a : adj[u])
{
if(t + a.w > 2000) continue;
if(d[a.v][t + a.w] > d[u][t] + a.c)
{
d[a.v][t + a.w] = d[u][t] + a.c;
pq.push({a.v, t + a.w, d[a.v][t + a.w]});
}
}
}
}
void Solve()
{
Dijkstra();
for(int i=2; i<=n; i++)
{
int res = oo;
for(int j=1; j<=2000; j++)
if(d[i][j] < oo) res = min(res, j * d[i][j]);
cout << (res < oo ? res : -1) << '\n';
}
}
int32_t main()
{
//freopen("sol.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
32004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
32772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
33516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
32720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
31884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
35120 KB |
Output is correct |
2 |
Incorrect |
73 ms |
35048 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
33620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
31924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
31936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
33604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |