QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#123311 | #995. 桥 | DrGilbert# | RE | 0ms | 0kb | C++20 | 905b | 2023-07-12 11:55:39 | 2023-07-12 11:55:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int dfn[N],low[N],stk[N];
int tot,num,col,top,bel[N];
struct node{int u,v;}e[N];
vector<vector<pair<int,int>>> G;
void tarjan(int x, int frm){
dfn[x]=low[x]=++tot;
stk[++top]=x;
for (auto [id,v]:G[x]){
if (!dfn[v]) tarjan(v,id),low[x]=min(low[x],low[v]);
else if (id!=frm) low[x]=min(low[x],dfn[v]);
}if (dfn[x]==low[x]){
int k;col++;
do{
k=stk[top--];bel[k]=col;
}while (k!=x);
}return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);cout.tie(nullptr);
int n,m;cin>>n>>m;G.resize(n+10);
for (int i=1;i<=m;i++){
cin>>e[i].u>>e[i].v;
G[e[i].u].emplace_back(i,e[i].v);
G[e[i].v].emplace_back(i,e[i].u);
}for (int i=1;i<=n;i++){
if (!dfn[i]) tarjan(i,0);
}for (int i=1;i<=m;i++){
if (bel[e[i].u]!=bel[e[i].v]){
cout<<e[i].u<<' '<<e[i].v<<endl;
}
}return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
24942 387166 12556 21443 22404 16376 11073 24296 1535 11968 23745 2818 5073 12731 22550 14761 24118 12008 22695 18979 15118 13639 2080 8721 692 22578 22581 15267 9278 4127 7457 21674 17693 23448 10949 23429 9700 6009 14140 5064 7742 15164 17336 1662 18903 9760 17645 19575 6540 11942 11 4937 15282 10...