이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 1;
const int oo = 1e16;
map<int,int> cc[N];
int n, m, color[N], dp[N];
struct mmb
{
int vertex, dlab, prec;
bool operator < (const mmb& other) const
{
return dlab > other.dlab;
}
};
struct tripple
{
int fi, se, th;
};
vector<tripple> adj[N];
void dijikstra()
{
dp[1] = 0;
priority_queue<mmb> Q;
Q.push({1, 0});
while(!Q.empty())
{
auto u = Q.top(); Q.pop();
// cout<<endl<<u.vertex<<" : "<<endl;
if(u.dlab != dp[u.vertex]) continue;
for(auto v : adj[u.vertex])
{
// cout << v.fi<<" - ";
if((cc[u.vertex][v.se] > 2 && u.prec == v.se) || (u.prec != v.se && cc[u.vertex][v.se] > 1))
{
// cout<<"1 : "<<dp[v.fi]<<" "<<u.dlab + v.th<<endl;
if(dp[v.fi] > u.dlab + v.th){
// cout<<"OK\n";
dp[v.fi] = u.dlab + v.th;
Q.push({v.fi, dp[v.fi], v.se});
}
}
else
{
// cout<<"2 : "<<dp[v.fi]<<" "<<u.dlab + v.th<<endl;
if(dp[v.fi] > u.dlab)
{
// cout<<"OK\n";
dp[v.fi] = u.dlab;
Q.push({v.fi, dp[v.fi], v.se});
}
}
}
}
}
int32_t main()
{
// freopen("test.inp", "r" ,stdin);
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) dp[i] = oo;
for(int i = 1; i <= m; i++)
{
int a, b, c, p;
cin >> a >> b >> c >> p;
adj[a].push_back({b, c, p});
adj[b].push_back({a, c, p});
cc[a][c]++;
cc[b][c]++;
}
dijikstra();
if(dp[n] == oo) cout<<"-1";
else cout << dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |