This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
Compilation message (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... |