#include <bits/stdc++.h>
//code
#define fl(i,x,y,z) for(int i=x;i<=y;i=i+z)
#define fn(i,x,y,z) for(int i=x;i>=y;i=i-z)
#define rep(i,x,y) for(int i=x;i<y;i=i+1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define tle cout<<"tle"<<endl
#define edl cout<<"\n"
#define el "\n"
#define getbit(x,i) ((x>>i)&1)
#define bitcnt __builtin_popcount
//ham
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
#define m_p make_pair
//#define int long long
using namespace std;
const ll mod=1e9+7;
vector< pii > a[200005];
vector<pair<int,pii>> g[200005];
int d[200005];
int t[200005];
bool vis[200005];
void dij(int x)
{
fl(i,1,200005,1) d[i] = 1e9;
priority_queue< pii , vector < pii > , greater < pii > > q;
d[x] = 0;
q.push(m_p(0, x));
while (!q.empty())
{
auto p1 = q.top();
int W = p1.fi;
int x = p1.se;
q.pop();
if (vis[x])
continue;
vis[x] = 1;
for (auto p2 : a[x])
{
int y = p2.fi;
int w = p2.se;
if (vis[y] || d[y] < W + w)
continue;
d[y] = W + w;
q.push({W + w, y});
}
}
}
void sol()
{
int n,m,x,y,c,p;
cin >> n >> m;
fl(i,1,m,1)
{
cin >> x >> y >> c >> p;
g[x].push_back({c, {y, p}});
g[y].push_back({c, {x, p}});
a[x].push_back({y, p});
a[y].push_back({x, p});
}
int cur = n;
fl(i,1,n,1)
{
sort(g[i].begin(), g[i].end());
for (auto x : g[i])
t[x.fi] += x.se.se;
for (auto x : g[i])
{
if (!vis[x.fi])
{
++cur;
a[i].push_back(m_p(cur,0));
}
vis[x.fi] = 1;
a[cur].push_back(m_p(x.se.fi, t[x.fi] - x.se.se));
a[x.se.fi].push_back(m_p(cur, 0));
}
for (auto x : g[i])
{
t[x.fi] = 0;
vis[x.fi] = 0;
}
}
dij(1);
if (d[n] == 1e9) cout << "-1";
else cout << d[n];
}
signed main()
{
// freopen("task.inp","r",stdin);
// freopen("task.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sol();
return 0;
}
/* /\_/\
( ._. )
/ >V< \
*/
Compilation message
Main.cpp: In function 'void dij(int)':
Main.cpp:31:24: warning: iteration 200004 invokes undefined behavior [-Waggressive-loop-optimizations]
31 | fl(i,1,200005,1) d[i] = 1e9;
| ~~~~~^~~~~
Main.cpp:3:34: note: within this loop
3 | #define fl(i,x,y,z) for(int i=x;i<=y;i=i+z)
......
31 | fl(i,1,200005,1) d[i] = 1e9;
| ~~~~~~~~~~
Main.cpp:31:2: note: in expansion of macro 'fl'
31 | fl(i,1,200005,1) d[i] = 1e9;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10588 KB |
Output is correct |
2 |
Correct |
5 ms |
10496 KB |
Output is correct |
3 |
Correct |
5 ms |
10588 KB |
Output is correct |
4 |
Correct |
5 ms |
10636 KB |
Output is correct |
5 |
Correct |
5 ms |
10588 KB |
Output is correct |
6 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
23496 KB |
Output is correct |
2 |
Correct |
37 ms |
16596 KB |
Output is correct |
3 |
Correct |
99 ms |
29132 KB |
Output is correct |
4 |
Correct |
54 ms |
18892 KB |
Output is correct |
5 |
Runtime error |
97 ms |
57176 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10588 KB |
Output is correct |
2 |
Correct |
5 ms |
10496 KB |
Output is correct |
3 |
Correct |
5 ms |
10588 KB |
Output is correct |
4 |
Correct |
5 ms |
10636 KB |
Output is correct |
5 |
Correct |
5 ms |
10588 KB |
Output is correct |
6 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |