#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define left ind+ind
#define right ind+ind+1
#define mid (l+r)/2
#define FAST_IO ios_base::sync_with_stdio(false);
#define endl '\n'
const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9;
const int N = 1e5 + 5;
const int M = 1e4 + 5;
const int SQ = 350;
const int MOD = 998244353;
typedef pair <int,int> pii;
struct comp_node {
int cur;
long long cost,mnu,mnv;
};
bool operator < (comp_node x,comp_node y) {
return x.cost > y.cost;
}
struct node {
int cur;
long long cost;
};
bool operator < (node x,node y) {
return x.cost > y.cost;
}
priority_queue <node> Q;
priority_queue <comp_node> CQ;
vector <pair <int,int> > ed[N];
int n,m,s,t,u,v;
long long sp,cu[N],cv[N],ans = LINF,vis[N];
void sp_s(){
for (int i = 1 ; i <= n ; i++) vis[i] = LINF;
CQ.push({s,0,cu[s],cv[s]});
while(len(CQ)) {
auto temp = CQ.top();
CQ.pop();
int cur = temp.cur;
long long cost = temp.cost,mnu = temp.mnu,mnv = temp.mnv;
if (vis[cur] < cost) continue;
vis[cur] = cost;
if (cur == t) ans = min(ans,mnu + mnv);
for (auto i : ed[cur]) CQ.push({i.fi,cost + i.sc,min(mnu,cu[i.fi]),min(mnv,cv[i.fi])});
}
while(len(CQ)) CQ.pop();
memset(vis,0,sizeof vis);
}
void sp_u(){
Q.push({u,0});
while(len(Q)) {
auto temp = Q.top();
Q.pop();
int cur = temp.cur;
long long cost = temp.cost;
if (vis[cur]) continue;
vis[cur] = 1;
cu[cur] = cost;
for (auto i : ed[cur]) Q.push({i.fi,cost + i.sc});
}
memset(vis,0,sizeof vis);
while(len(Q)) Q.pop();
}
void sp_v(){
Q.push({v,0});
while(len(Q)) {
auto temp = Q.top();
Q.pop();
int cur = temp.cur;
long long cost = temp.cost;
if (vis[cur]) continue;
vis[cur] = 1;
cv[cur] = cost;
for (auto i : ed[cur]) Q.push({i.fi,cost + i.sc});
}
memset(vis,0,sizeof vis);
while(len(Q)) Q.pop();
}
int main() {
scanf("%d %d %d %d %d %d",&n,&m,&s,&t,&u,&v);
for (int i = 1 ; i <= m ; i++) {
int u,v,c;
scanf("%d %d %d",&u,&v,&c);
ed[u].pb(mp(v,c));
ed[v].pb(mp(u,c));
}
sp_u();
sp_v();
sp_s();
printf("%lld\n",min(ans,cu[v]));
}
Compilation message
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:105:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d %d %d",&n,&m,&s,&t,&u,&v);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:108:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&u,&v,&c);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
834 ms |
30628 KB |
Output is correct |
2 |
Execution timed out |
2017 ms |
263168 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
657 ms |
263168 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1887 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
834 ms |
30628 KB |
Output is correct |
2 |
Execution timed out |
2017 ms |
263168 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |