# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702524 | 2023-02-24T09:49:51 Z | 1075508020060209tc | Olympic Bus (JOI20_ho_t4) | C++14 | 65 ms | 12208 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); } } 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; } int ans=1e18; int cnt=0; for(int i=1;i<=n;i++){ int a=scc[es[i].x];int b=scc[es[i].y]; if(a==scc[1]&&b==scc[n]){ cnt++; ans=min(ans,es[i].d); } if(a==scc[n]&&b==scc[1]){ cnt++; ans=min(ans,es[i].d); } } if(cnt>=2){ cout<<ans;return 0; } cout<<-1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9700 KB | Output is correct |
3 | Incorrect | 6 ms | 9708 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 65 ms | 12208 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 9680 KB | Output is correct |
2 | Correct | 5 ms | 9684 KB | Output is correct |
3 | Correct | 42 ms | 11472 KB | Output is correct |
4 | Correct | 5 ms | 9684 KB | Output is correct |
5 | Correct | 53 ms | 12080 KB | Output is correct |
6 | Correct | 5 ms | 9692 KB | Output is correct |
7 | Correct | 5 ms | 9684 KB | Output is correct |
8 | Incorrect | 48 ms | 12056 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9684 KB | Output is correct |
2 | Correct | 6 ms | 9700 KB | Output is correct |
3 | Incorrect | 6 ms | 9708 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |