이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fixbug false
void SETIO(string name = ""){
if (name=="") return;
freopen((name+".inp").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
return;
}
const int maxn = 1e5;
const int maxm = 2e5;
const ll INF = (ll)1e18+7;
struct _data{
ll cost; int u , color;
bool operator > (const _data &other) const{
return cost > other.cost;
}
bool operator < (const _data &other) const{
return cost < other.cost;
}
};
struct Node{
int to , c , p;
};
vector<Node> g[maxn+2];
ll sum[maxm+2];
bool used[maxn+2] = {};
map<pair<int,int> , bool> vis;
int n , m;
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
SETIO("");
cin >> n >> m;
for (int i = 1; i <= m; ++i){
int u , v , c , p;
cin >> u >> v >> c >> p;
g[u].push_back({v , c , p});
g[v].push_back({u , c , p});
}
//... build the base
priority_queue<_data,vector<_data>,greater<_data>> q;
ll ans = INF;
q.push({0 , 1 , m + 1});
while (q.size()){
ll cost = q.top().cost;
int u = q.top().u;
int color = q.top().color;
q.pop();
if (vis[{u , color}] == 1) continue;
if (fixbug){
cout << "(DEBUG)\n";
cout << u << ' ' << color << ' ' << cost << '\n';
}
vis[{u , color}] = true;
if (u == n) ans = min(ans , cost);
for (auto& x : g[u])
sum[x.c] += x.p;
for (auto& x : g[u]){
int v = x.to , c = x.c , p = x.p;
if (c == color) continue;
if (!vis[{v , m + 1}]) q.push({cost + p , v , m + 1});
if (!vis[{v , c}]) q.push({cost + sum[c] - p , v , c});
if (fixbug){
cout << "(DEBUG ORZZZ)\n";
cout << u << "->" << v << ' ' << c << ' ' << sum[c] << '\n';
cout << '\n';
}
}
for (auto& x : g[u])
sum[x.c] -= x.p;
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void SETIO(std::string)':
Main.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | freopen((name+".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |