## Submission #623607

# Submission time Handle Problem Language Result Execution time Memory
623607 2022-08-06T05:10:53 Z Do_you_copy Commuter Pass (JOI18_commuter_pass) C++17
0 / 100
2000 ms 24772 KB
```#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;

ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}

//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
const ll inf = 1e15;
int n, m;
int s, t, x, y;
ll d[maxN];
ll dp[maxN];
vector <int> trace[maxN];
vector <int> dag[maxN];
bool visited[maxN];
int deg[maxN];
void Dijkstra(int s, vector <ll> &res, bool flag){
set <pii> S;
fill(res.begin(), res.end(), inf);
res[s] = 0;
S.insert({0, s});
while (!S.empty()){
auto r = S.begin(); S.erase(S.begin());
if (d[r->se] != r->fi) continue;
int u = r->se;
for (const pii &i: adj[u]){
int v = i.fi;
if (res[v] > res[u] + i.se){
res[v] = res[u] + i.se;
S.insert({dp[v], v});
if (flag){
trace[v].clear();
trace[v].pb(u);
}
}
else if (res[v] == res[u] + i.se && flag){
trace[v].pb(u);
}
}
}
}

void build_dag(int s){
queue <int> Q;
Q.push(s);
while (!Q.empty()){
int r = Q.front(); Q.pop();
if (visited[r]) continue;
visited[r] = 1;
for (int v: trace[r]){
if (!visited[v]){
Q.push(v);
dag[v].pb(r);
}
}
}
}

void Init(){
cin >> n >> m >> s >> t >> x >> y;
for (int i = 1; i <= m; ++i){
int u, v, w;
cin >> u >> v >> w;
}
vector <ll> d(n + 1), e(n + 1), f(n + 1);
Dijkstra(t, d, 1);
Dijkstra(x, e, 0);
Dijkstra(y, f, 0);
build_dag(s);
for (int i = 1; i <= n; ++i){
for (int j: dag[i]) ++deg[j];
}
queue <int> Q;
for (int i = 1; i <= n; ++i){
dp[i] = f[i];
if (!deg[i]) Q.push(i);
}
ll ans = inf;
while (!Q.empty()){
int u = Q.front(); Q.pop();
ans = min(ans, e[u] + dp[u]);
for (const int &i: dag[u]){
dp[i] = min(dp[i], dp[u]);
if (!--deg[i]){
Q.push(i);
}
}
}
cout << ans;
}

int main(){
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
}
```

### Compilation message

```commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
119 |         freopen(taskname".inp", "r", stdin);
|         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~```

#### Subtask #1 0 / 16.0

# Verdict Execution time Memory Grader output
1 Execution timed out 2080 ms 24772 KB Time limit exceeded
2 Halted 0 ms 0 KB -

#### Subtask #2 0 / 15.0

# Verdict Execution time Memory Grader output
1 Execution timed out 2077 ms 23772 KB Time limit exceeded
2 Halted 0 ms 0 KB -

#### Subtask #3 0 / 24.0

# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8440 KB Output isn't correct
2 Halted 0 ms 0 KB -

#### Subtask #4 0 / 45.0

# Verdict Execution time Memory Grader output
1 Execution timed out 2080 ms 24772 KB Time limit exceeded
2 Halted 0 ms 0 KB -