Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
pdp-camp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Public
pdp-camp
Commits
2dadbc50
Commit
2dadbc50
authored
May 09, 2017
by
Panagiotis Kostopanagiotis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UVA OJ - 796, Bridge finding
parent
0d52e0ee
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
critical.cpp
2017/critical.cpp
+70
-0
No files found.
2017/critical.cpp
0 → 100644
View file @
2dadbc50
#include <cstdio>
#include <algorithm>
#include <vector>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
using
namespace
std
;
typedef
pair
<
int
,
int
>
pii
;
int
N
,
cnt
=
0
;
vector
<
vector
<
int
>
>
G
;
vector
<
int
>
low
,
time
,
visited
;
vector
<
pii
>
bridges
;
void
dfs
(
int
u
,
int
p
)
{
time
[
u
]
=
++
cnt
;
low
[
u
]
=
time
[
u
];
for
(
int
i
=
0
;
i
<
G
[
u
].
size
();
i
++
)
{
int
v
=
G
[
u
][
i
];
if
(
v
==
p
)
continue
;
if
(
!
time
[
v
]
)
{
dfs
(
v
,
u
);
if
(
time
[
u
]
<
low
[
v
]
)
bridges
.
pb
(
mp
(
min
(
u
,
v
),
max
(
u
,
v
)
)
);
low
[
u
]
=
min
(
low
[
u
],
low
[
v
]
);
}
else
{
low
[
u
]
=
min
(
low
[
u
],
time
[
v
]
);
}
}
}
int
main
(
void
)
{
while
(
scanf
(
"%d"
,
&
N
)
==
1
)
{
G
.
resize
(
N
+
1
);
low
.
resize
(
N
+
1
,
0
);
time
.
resize
(
N
+
1
,
0
);
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
int
u
,
e
,
v
;
scanf
(
"%d (%d)"
,
&
u
,
&
e
);
for
(
int
j
=
0
;
j
<
e
;
j
++
)
{
scanf
(
"%d"
,
&
v
);
G
[
u
].
pb
(
v
);
}
}
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
if
(
!
time
[
i
]
)
dfs
(
i
,
-
1
);
}
sort
(
bridges
.
begin
(),
bridges
.
end
()
);
printf
(
"%d critical links
\n
"
,
bridges
.
size
()
);
for
(
int
i
=
0
;
i
<
bridges
.
size
();
i
++
)
{
printf
(
"%d - %d
\n
"
,
bridges
[
i
].
X
,
bridges
[
i
].
Y
);
}
printf
(
"
\n
"
);
cnt
=
1
;
bridges
.
clear
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
G
[
i
].
clear
();
low
.
clear
();
time
.
clear
();
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment