이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5;
const int M = 2e5;
const ll inf = 1e18;
vector<pair<int,ll>>e[N+M*2];
ll dist[N+M*2];
map <int,ll> f[N];
vector <array<ll,3>> edges[M];
priority_queue <pair<int,ll>> pq;
int vis[N];
int cnt = 0;
int main(){
int n,m;
cin>>n>>m;
for(int i = 0;i < m;i++){
int u,w,c,d;
cin>>u>>w>>c>>d;
u--;w--;c--;
f[u][c]+=d;
f[w][c]+=d;
edges[c].push_back({u,w,d});
}
///two consective of the same color has a special case
///how to implement??? is the only way to make additions to graph?? ew
cnt = n;
for(int i = 0;i < m;i++){
for(auto j:edges[i]){
e[j[0]].push_back({j[1],min(j[2],f[j[0]][i] - j[2])});
e[j[1]].push_back({j[0],min(j[2],f[j[1]][i] - j[2])});
if(!vis[j[0]]){
vis[j[0]] = cnt++;
}
if(!vis[j[1]]){
vis[j[1]] = cnt++;
}
//cout<<vis[j[0]]<<' '<<vis[j[1]]<<'\n';
e[j[1]].push_back({vis[j[0]],0});
e[j[0]].push_back({vis[j[1]],0});
e[vis[j[0]]].push_back({j[1],f[j[0]][i] - j[2]});
e[vis[j[1]]].push_back({j[0],f[j[1]][i] - j[2]});
}
for(auto j:edges[i]){
vis[j[0]] = 0;
vis[j[1]] = 0;
}
}
for(int i = 0;i < cnt;i++){
dist[i] = inf;
}
dist[0] = 0;
pq.push({0,0});
while(!pq.empty()){
ll d = -pq.top().first;
int id = pq.top().second;
pq.pop();
if(d > dist[id])continue;
for(auto i:e[id]){
if(dist[i.first] > i.second + d){
dist[i.first] = i.second + d;
pq.push({-dist[i.first],i.first});
}
}
}
cout<<dist[n - 1]<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |