QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#792903#995. 桥ZaSh1X1ngWA 57ms13428kbC++171.5kb2024-11-29 14:57:332024-11-29 14:57:39

Judging History

你现在查看的是最新测评结果

  • [2024-11-29 14:57:39]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:13428kb
  • [2024-11-29 14:57:33]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
auto debug(auto ...b){((cerr << b << ' ') , ...); cerr << '\n';}
#else
#define debug(...) 0717
#endif

using ll = long long;
using uint = unsigned;
using ull = unsigned long long;

const int INF = 0x3F3F3F3F;
const ll INFl = 0x3F3F3F3F3F3F3F3F;

#define all(x) x.begin(),x.end()
#define r_all(x) x.rbegin(),x.rend()

const int N = 1e5 + 5;
const int M = 5e5 + 5;

int n , m;

struct edge {
	int to , nxt;
}e[M << 1];
int head[N] , cnt = 1;
void adde(int u , int v){
	e[ ++ cnt] = {v , head[u]};
	head[u] = cnt;
	e[ ++ cnt] = {u , head[v]};
	head[v] = cnt;
}
#define out(u) for(int i = head[u]; i; i = e[i].nxt)

int dfn[N] , low[N] , idx;
vector<int> bri;
void tarjan(int u , int in_edge){
	dfn[u] = low[u] = ++ idx;
	out(u){
		int v = e[i].to;
		if(!dfn[v]) {
			tarjan(v , i);
			low[u] = min(low[u] , low[v]);
		}
		else if((i ^ 1) != in_edge){
			low[u] = min(low[u] , dfn[v]);
		}
	}
	if(low[u] == dfn[u]){
		bri.push_back(in_edge & (in_edge ^ 1));
	}
//	debug(u , dfn[u] , low[u]);
}

signed main() {
#ifdef LOCAL
#elif defined(ONLINE_JUDGE)
#else
#endif
	
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= m; ++ i){
		int u , v; cin >> u >> v;
		if(u == v) continue;
		adde(u , v);
	}
	
	for(int i = 1; i <= n; ++ i){
		if(!dfn[i]) tarjan(i , 0);
	}
	
	for(auto i : bri){
		if(!i) continue;
		int v = e[i].to , u = e[i + 1].to;
		cout << u << " " << v << '\n';
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 57ms
memory: 13428kb

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: 12ms
memory: 6056kb

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: 17ms
memory: 10352kb

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:

40810 34151
33227 3470
41747 9870
15632 36765
9934 42389
19160 30392
26463 23661
32458 7635
38679 24909
6034 198
35426 1189
11533 37842
34968 34953
38722 11709
16187 39109
30073 30995
28184 22432
19830 34036
31269 26255
35386 30362
32145 32387
5694 20147
30723 12783
32950 37772
4153 11464
37306 1520...

result:

wrong answer 1st lines differ - expected: '1349 20915', found: '40810 34151'