#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=1e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
ll n,m;
struct edge{
ll des,clr,cst;
edge(int _des,int _clr,int _cst):des(_des),clr(_clr),cst(_cst){}
};
vector<edge> G[MAX];
vector<pll> G2[MAX*3];
int main() {
speed;
cin>>n>>m;
for (int i=0;i<m;i++) {
ll a,b,c,p;
cin>>a>>b>>c>>p;
G[a].emplace_back(b,c,p);
G[b].emplace_back(a,c,p);
G2[a].push_back({b,p});
G2[b].push_back({a,p});
}
ll now=n+1;
for (int i=1;i<=n;i++) {
map<int,vector<pll> > ttl;
for (auto eg:G[i]) ttl[eg.clr].emplace_back(eg.des,eg.cst);
for (auto [clr,egs]:ttl) {
ll ttlw=0;
for (auto eg:egs) ttlw+=eg.second;
G2[i].push_back({now,0});
for (auto eg:egs) {
G2[now].emplace_back(eg.first,ttlw-eg.second);
G2[eg.first].emplace_back(now,0);
}
// cout<<i<<" "<<clr<<" "<<now<<"\n";
now++;
}
}
// for (int i=1;i<now;i++) {
// cout<<i<<".\n";
// for (auto j:G2[i]) {
// cout<<j.first<<" "<<j.second<<"\n";
// }
// cout<<"----\n";
// }
priority_queue<pll> D;
vector<bool> vis(now+1,0);
vector<ll> dis(now+1,oo);
dis[1]=0;
D.emplace(0,1);
while (!D.empty()) {
while (!D.empty() and vis[D.top().second]) D.pop();
if (D.empty()) break;
int v=D.top().second;
D.pop();
vis[v]=true;
for (auto [u,w]:G2[v]) {
if (!vis[u] and dis[v]+w<dis[u]) {
dis[u]=dis[v]+w;
D.emplace(-dis[u],u);
}
}
}
cout<<dis[n]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9816 KB |
Output is correct |
2 |
Incorrect |
3 ms |
9820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
31440 KB |
Output is correct |
2 |
Correct |
49 ms |
19356 KB |
Output is correct |
3 |
Correct |
124 ms |
42952 KB |
Output is correct |
4 |
Correct |
61 ms |
23504 KB |
Output is correct |
5 |
Runtime error |
257 ms |
117260 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
9816 KB |
Output is correct |
2 |
Incorrect |
3 ms |
9820 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |