1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "sabotaz.h"
#include "message.h"
#include<iostream>
#include<stdio.h>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
const int MAXN = 200000;
int n=NumberOfIsles(); 
vector<int> g[MAXN];
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN];
int IS_BRIDGE=0;
void dfs (int v, int p = -1) {
	used[v] = true;
	tin[v] = fup[v] = timer++;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (to == p)  continue;
		if (used[to])
			fup[v] = min (fup[v], tin[to]);
		else {
			dfs (to, v);
			fup[v] = min (fup[v], fup[to]);
			if (fup[to] > tin[v]/* && doub[(to<v)?to:v][(to>v)?to:v]<2*/)
				if((i+1>=g[v].size() || g[v][i+1]!=g[v][i+1]) && (i-1<0 || g[v][i-1]!=g[v][i]) )
					IS_BRIDGE++;
		}
	}
}
 
void find_bridges() {
	timer = 0;
	for (int i=0; i<n; ++i)
		used[i] = false;
	for (int i=0; i<n; ++i)
		if (!used[i])
			dfs (i);
}

int main()
{
	long long int m=NumberOfBridges();
	for(long long int ii=0;ii<m;ii++)
	{
		g[BridgeEndB(ii)].push_back(BridgeEndA(ii));
		g[BridgeEndA(ii)].push_back(BridgeEndB(ii));
	}
	for(int j=0;j<n;j++)
	{
		sort(g[j].begin(),g[j].end());
	}
	find_bridges();
	cout << IS_BRIDGE << endl;
	return 0;
}