QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290411 | #995. 桥 | pangwt | WA | 145ms | 19368kb | C++20 | 1.0kb | 2023-12-24 23:11:32 | 2023-12-24 23:11:32 |
Judging History
answer
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N=100010,M=100100;
int n,m,a,b,cnt;
struct edge{int u,v;};
vector<edge>e;
vector<int>h[N];
int dfn[N],low[N],tot;
struct bridge{
int x,y;
bool operator<(const bridge &t)const{
if(x==t.x)return y<t.y;
return x<t.x;
}
}bri[M];
void add(int a,int b){
e.push_back({a,b});
h[a].push_back(e.size()-1);
}
void tarjan(int x,int in_edge){
dfn[x]=low[x]=++tot;
for(int i=0;i<h[x].size();i++){
int j=h[x][i], y=e[j].v;
if(!dfn[y]){//若y尚未访问
tarjan(y,j);
low[x]=min(low[x],low[y]);
if(low[y]>dfn[x]){
bri[cnt++]={x,y};
}
}
else if(j!=(in_edge^1))//不是反边
low[x]=min(low[x],dfn[y]);
}
}
int main(){
cin>>n>>m;
while(m --){
cin>>a>>b;
add(a,b),add(b,a);
}
for(int i=1; i<=n; i++)
if(!dfn[i])tarjan(i,0);
sort(bri,bri+cnt);
for(int i=0;i<cnt;i++)
printf("%d %d\n",bri[i].x,bri[i].y);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 145ms
memory: 19368kb
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...
output:
result:
ok 0 lines
Test #2:
score: 0
Accepted
time: 25ms
memory: 9044kb
input:
10599 87159 4698 4000 60 4705 1476 5947 7273 1716 8004 3018 10094 1717 3092 3493 2613 9681 5427 3723 2510 6343 10113 6322 9257 634 4996 10197 9918 5582 6348 9561 10536 9777 8133 540 1917 7838 6666 2220 7951 815 2873 977 9397 4991 3529 1395 1426 3874 6379 9098 9504 3437 9076 9134 4321 3879 10252 9390...
output:
result:
ok 0 lines
Test #3:
score: -100
Wrong Answer
time: 57ms
memory: 13064kb
input:
43236 126833 40500 20695 21481 27642 28098 41772 412 7750 5862 39561 21777 22303 7868 21217 31658 34299 18532 10934 21931 31023 42926 15624 40332 18017 12484 8663 21927 7910 12504 17943 4379 10252 3523 21794 18641 1965 18633 25061 14639 10800 35958 1441 35044 20249 31491 38161 5749 4468 13403 8413 3...
output:
2 37463 130 17077 265 36389 426 8866 511 7781 553 8977 608 2833 695 32769 727 38899 998 16325 1018 22513 1309 33860 1328 8983 1390 24240 1592 7049 1598 38439 1653 23236 1715 10750 1928 2832 1977 18096 2055 20006 2082 21718 2083 38542 2118 11083 2127 40750 2299 463 2321 22010 2353 4623 2402 28207 246...
result:
wrong answer 1st lines differ - expected: '1349 20915', found: '2 37463'