이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n';
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}
void code(){
int n,m,s,t,u,v;cin>>n>>m>>s>>t>>u>>v;
vector<int>komsu[n+1];
vector<ll>cos[n+1];
for(int i=0;i<m;i++){
int x,y,c;cin>>x>>y>>c;
komsu[x].pb(y);
komsu[y].pb(x);
cos[x].pb(c);
cos[y].pb(c);
}
ll a[n+1],b[n+1];
for(ll &x:a)
x=inf;
for(ll &x:b)
x=inf;
priority_queue<pair<ll,int>>q;
q.push({0,u});
while(q.size()){
ll dis=q.top().fr;
int pos=q.top().sc;
q.pop();
if(a[pos]!=inf)
continue;
a[pos]=-dis;
for(int i=0;i<komsu[pos].size();i++){
if(a[komsu[pos][i]]!=inf)continue;
q.push({dis-cos[pos][i],komsu[pos][i]});
}
}
q.push({0,v});
while(q.size()){
ll dis=q.top().fr;
int pos=q.top().sc;
q.pop();
if(b[pos]!=inf)
continue;
b[pos]=-dis;
for(int i=0;i<komsu[pos].size();i++){
if(b[komsu[pos][i]]!=inf)continue;
q.push({dis-cos[pos][i],komsu[pos][i]});
}
}
priority_queue<vector<ll>>pq;
pq.push({0,-a[s]-b[s],a[s],b[s],s});
ll ans=a[v];
bool vis[n+1];for(bool &x:vis)x=false;
while(pq.size()){
int pos=pq.top()[4];
ll dis=pq.top()[0],dis1=pq.top()[2],dis2=pq.top()[3];
if(pos==t){
ans=min(ans,-pq.top()[1]);
break;
}
pq.pop();
if(vis[pos])continue;
vis[pos]=true;
for(int i=0;i<komsu[pos].size();i++){
if(vis[komsu[pos][i]])continue;
ll x=min(dis1,a[komsu[pos][i]]),y=min(dis2,b[komsu[pos][i]]);
pq.push({dis-cos[pos][i],-x-y,x,y,komsu[pos][i]});
}
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int t=1;
if(!t)cin>>t;
while(t--){code();cout<<endl;}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void code()':
commuter_pass.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<komsu[pos].size();i++){
| ~^~~~~~~~~~~~~~~~~~
commuter_pass.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0;i<komsu[pos].size();i++){
| ~^~~~~~~~~~~~~~~~~~
commuter_pass.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=0;i<komsu[pos].size();i++){
| ~^~~~~~~~~~~~~~~~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:82:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~
commuter_pass.cpp:82:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |