이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define TASK ""
# define FOR(i,x,y) for(int i = x; i <= y; ++i)
# define all(x) x.begin(), x.end()
# define pii pair< ll , ll >
template <class T>
bool inArr(T obj, vector<T> x){
return find(all(x), obj) != x.end();
}
int getbit(int i, int j){
return ( 1 << (j-1) ) & i;
}
const long long MAXN = 1e5 + 5;
ll N, M;
struct binh{
ll v,c,p;
};
vector< binh > g[MAXN];
map < ll , ll > m[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(TASK".inp", "r")){
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
cin >>N >> M;
for(int i = 1; i <= M; ++i){
ll u,v,c,p;
cin >> u >> v >> c >> p;
g[u].push_back({v,c,p});
g[v].push_back({u,c,p});
++m[u][c];
++m[v][c];
}
priority_queue< pii, vector< pii >, greater< pii > > q;
q.push({0, 1});
vector< ll > d(N + 1, LLONG_MAX);
vector< ll > vis(N + 1, 0);
d[1] = 0;
while(q.size()){
auto [cost, u] = q.top(); q.pop();
if(vis[u]) continue;
vis[u] = 1;
for(auto [v, c, p] : g[u]){
if(m[u][c] == 1){
d[v] = min(d[v], cost);
q.push({cost, v});
}
else if(d[v] > cost + p){
q.push({d[v] = cost + p, v});
}
}
}
if(d[N] != LLONG_MAX) cout << d[N]; else cout << -1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(TASK".out", "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... |