이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class Edge {
public:
int node;
ll weight;
int color;
int cost;
Edge(int n, int c, int co) {
node = n;
weight = 0;
color = c;
cost = co;
}
};
typedef pair<ll, int> pii;
const int MAXN = 1e5;
const int MAXM = 2e5;
int n, m;
vector<Edge> edges[MAXN];
ll dist[MAXN];
ll min(ll a, ll b) {
if (a < b) return a;
return b;
}
void dijkstra() {
dist[0] = 0;
set<pii> pq;
pq.insert(pii(0, 0));
while (!pq.empty()) {
pii cur = *(pq.begin());
pq.erase(cur);
for (Edge e: edges[cur.second]) {
int next = e.node;
if (dist[next] == -1 || dist[cur.second]+e.weight < dist[next]) {
pq.erase(pii(dist[next], next));
dist[next] = dist[cur.second]+e.weight;
pq.insert(pii(dist[next], next));
}
}
}
}
void adj_edges(int i) {
for (int j = 0; j < edges[i].size(); ) {
int orig = j;
while (j < edges[i].size() && edges[i][orig].color == edges[i][j].color) j++;
if (j == orig+1) continue;
else for (int k = orig; k < j; k++) edges[i][k].weight = edges[i][k].cost;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y, c, co;
cin >> x >> y >> c >> co;
x--; y--; c--;
edges[x].push_back(Edge(y, c, co));
edges[y].push_back(Edge(x, c, co));
}
for (int i = 0; i < n; i++) adj_edges(i);
fill(dist, dist+n, -1);
dijkstra();
cout << dist[n-1] << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void adj_edges(int)':
Main.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int j = 0; j < edges[i].size(); ) {
| ~~^~~~~~~~~~~~~~~~~
Main.cpp:55:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while (j < edges[i].size() && edges[i][orig].color == edges[i][j].color) j++;
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |