이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<ll,int>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct edge{
int x;
int boja;
ll v;
};
ll maks = 1e9;
struct node{
int cale;
int x;
ll v;
};
bool operator < (const node &a, const node &b){
return a.v < b.v;
}
bool operator > (const node &a, const node &b){
return a.v > b.v;
}
int n,m;
vector<edge> graf[100005];
map<pii,ll>dist;
bool cmp(edge a, edge b){
if(a.boja < b.boja)return 1;
return 0;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
maks *= maks;
cin >> n >> m;
ff(i,1,m){
int a,b,c,d;
cin >> a >> b >> c >> d;
graf[a].pb({b,c,d});
graf[b].pb({a,c,d});
}
ff(i,1,n)sort(graf[i].begin(), graf[i].end(), cmp);
priority_queue<node, vector<node>, greater<node>> pq;
pq.push({-1,1,0});
while(!pq.empty()){
node sta = pq.top();
pq.pop();
int last = 0;
ll sum = 0;
int koji = sta.x;
int od = sta.cale;
od -= n;
int len = graf[koji].size();
if(len == 0)continue;
ff(i,0,len - 1){
if(graf[koji][i].x == od)continue;
if(graf[koji][i].boja != graf[koji][last].boja){
ff(j,last,i-1){
ll duz1 = graf[koji][j].v + sta.v;
int gde = graf[koji][j].x;
if(gde == od)continue;
if(dist.find({koji+n,gde}) == dist.end() || dist[{koji+n,gde}] > duz1){
dist[{koji+n,gde}] = duz1;
pq.push({koji+n,gde,duz1});
}
duz1 = sta.v + sum - graf[koji][j].v;
if(dist.find({koji,gde}) == dist.end() || dist[{koji,gde}] > duz1){
dist[{koji,gde}] = duz1;
pq.push({koji,gde,duz1});
}
}
last = i;
sum = graf[koji][i].v;
}
else{
sum += graf[koji][i].v;
}
}
ff(j,last,len-1){
ll duz1 = graf[koji][j].v + sta.v;
int gde = graf[koji][j].x;
if(gde == od)continue;
if(dist.find({koji+n,gde}) == dist.end() || dist[{koji+n,gde}] > duz1){
dist[{koji+n,gde}] = duz1;
pq.push({koji+n,gde,duz1});
}
duz1 = sta.v + sum - graf[koji][j].v;
if(dist.find({koji,gde}) == dist.end() || dist[{koji,gde}] > duz1){
dist[{koji,gde}] = duz1;
pq.push({koji,gde,duz1});
}
}
}
ll res = maks;
ff(i,1,2*n){
if(dist.find({i,n}) != dist.end())res = min(res, dist[{i,n}]);
}
if(res < maks)cout << res << "\n";
else cout << -1 << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
Main.cpp:58:5: note: in expansion of macro 'ff'
58 | ff(i,1,m){
| ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
Main.cpp:65:5: note: in expansion of macro 'ff'
65 | ff(i,1,n)sort(graf[i].begin(), graf[i].end(), cmp);
| ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
Main.cpp:80:9: note: in expansion of macro 'ff'
80 | ff(i,0,len - 1){
| ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
Main.cpp:83:17: note: in expansion of macro 'ff'
83 | ff(j,last,i-1){
| ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
Main.cpp:104:10: note: in expansion of macro 'ff'
104 | ff(j,last,len-1){
| ^~
Main.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
Main.cpp:120:5: note: in expansion of macro 'ff'
120 | ff(i,1,2*n){
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |