# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702575 | 2023-02-24T13:12:34 Z | 1075508020060209tc | Olympic Bus (JOI20_ho_t4) | C++14 | 62 ms | 13044 KB |
//#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second int n;int m; struct edg{ int x;int y;int d; }es[50005]; vector<int>e[200005]; vector<int>er[200005]; int vis[200005]; int sccid; int scc[200005]; vector<int>dfn; void dfs1(int nw){ vis[nw]=1; for(int i=0;i<e[nw].size();i++){ int id=e[nw][i]; int v=es[id].y; if(vis[v]){continue;} dfs1(v); } dfn.push_back(nw); } void dfs2(int nw){ scc[nw]=sccid; for(int i=0;i<e[nw].size();i++){ int id=e[nw][i]; int v=es[id].x; if(scc[v]){continue;} dfs2(v); } } void kosaraju(){ for(int i=1;i<=n;i++){ if(!vis[i]){ dfs1(i); } } sccid=1; reverse(dfn.begin(),dfn.end()); for(int i=0;i<dfn.size();i++){ int v=dfn[i]; if(scc[v]){continue;} sccid++; dfs2(v); } } int ch[500005]; void dfs(int nw){ ch[nw]=1; for(int i=0;i<e[nw].size();i++){ int id=e[nw][i]; int v=es[id].y; if(ch[v]){continue;} dfs(v); } } signed main(){ cin>>n>>m; for(int i=1;i<=m;i++){ int a;int b;int c;int d; cin>>a>>b>>c>>d; e[a].push_back(i); e[b].push_back(i); es[i]={a,b,d}; } kosaraju(); if(scc[1]==scc[n]){ cout<<0;return 0; } dfs(1); if(ch[n]){ int ans=1e16;int cnt=0; for(int i=1;i<=m;i++){ int a=scc[es[i].x];int b=scc[es[i].y];int d=es[i].d; if(a==scc[1]&&b==scc[n]){ ans=min(ans,d);cnt++; continue; } if(ch[a]&&b==scc[n]){ cnt++; } } if(cnt<=1){ans=1e16;} if(ans>=1e16){ cout<<-1; }else{ cout<<ans; } return 0; } for(int i=1;i<=n;i++){ ch[i]=0; } dfs(n); if(ch[1]){ int ans=1e16;int cnt=0; for(int i=1;i<=m;i++){ int a=scc[es[i].x];int b=scc[es[i].y];int d=es[i].d; if(a==scc[n]&&b==scc[1]){ ans=min(ans,d);cnt++; continue; } if(ch[a]&&b==scc[1]){ cnt++; } } if(cnt<=1){ans=1e16;} if(ans>=1e16){ cout<<-1; }else{ cout<<ans; } return 0; } cout<<-1;return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9684 KB | Output is correct |
3 | Incorrect | 6 ms | 9724 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 53 ms | 13044 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9784 KB | Output is correct |
3 | Correct | 42 ms | 12308 KB | Output is correct |
4 | Correct | 5 ms | 9684 KB | Output is correct |
5 | Correct | 62 ms | 13020 KB | Output is correct |
6 | Correct | 5 ms | 9684 KB | Output is correct |
7 | Correct | 5 ms | 9712 KB | Output is correct |
8 | Incorrect | 50 ms | 13024 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9684 KB | Output is correct |
3 | Incorrect | 6 ms | 9724 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |