이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, pair<long long, long long> > > adj[100005];
vector<pair<long long, long long> > vec[300005];
priority_queue<pair<long long, long long> > pq;
long long dist[300005], final[300005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, sz;
cin >> n >> m;
for (long long i=1; i<=m; i++)
{
long long u, v, c, p;
cin >> u >> v >> c >> p;
adj[u].push_back({c, {v, p}});
adj[v].push_back({c, {u, p}});
vec[u].push_back({v, p});
vec[v].push_back({u, p});
}
sz=n;
for (long long i=1; i<=n; i++)
{
sort(adj[i].begin(), adj[i].end());
long long ind=0;
for (long long j=1; j<adj[i].size(); j++)
{
if (adj[i][ind].first!=adj[i][j].first)
{
if (j-ind==1)
vec[i].push_back({adj[i][ind].second.first, 0});
else
{
long long sum=0;
for (long long k=ind; k<j; k++)
sum+=adj[i][k].second.second;
sz++;
vec[i].push_back({sz, 0});
for (long long k=ind; k<j; k++)
{
vec[adj[i][k].second.first].push_back({sz, 0});
vec[sz].push_back({adj[i][k].second.first, sum-adj[i][k].second.second});
}
}
ind=j;
}
}
long long j=adj[i].size();
if (j-ind==1)
vec[i].push_back({adj[i][ind].second.first, 0});
else
{
long long sum=0;
for (long long k=ind; k<j; k++)
sum+=adj[i][k].second.second;
sz++;
vec[i].push_back({sz, 0});
for (long long k=ind; k<j; k++)
{
vec[adj[i][k].second.first].push_back({sz, 0});
vec[sz].push_back({adj[i][k].second.first, sum-adj[i][k].second.second});
}
}
}
for (long long i=1; i<=sz; i++)
dist[i]=1e18;
dist[1]=0;
pq.push({0, 1});
while (!pq.empty())
{
long long u=pq.top().second;
pq.pop();
if (final[u])
continue;
final[u]=1;
for (long long i=0; i<vec[u].size(); i++)
{
long long v=vec[u][i].first, w=vec[u][i].second;
if (dist[u]+w<dist[v])
{
dist[v]=dist[u]+w;
if (!final[v])
pq.push({-dist[v], v});
}
}
}
if (dist[n]<5e17)
cout << dist[n];
else
cout << -1;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:28:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (long long j=1; j<adj[i].size(); j++)
| ~^~~~~~~~~~~~~~
Main.cpp:78:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (long long i=0; i<vec[u].size(); i++)
| ~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |