Burning Bridges Time limit: 5 Seconds Memory Limit: 32768 KB
Ferry Kingdom is a nice little country located on N Islands that's connected by M bridges. All bridges is very beautiful and is loved by everyone in the kingdom. Of course, the system of bridges is designed in such a-on-one, can-get-from-any-to-any other one.
But recently the great sorrow have come to the kingdom. Ferry Kingdom was conquered by the armies of the great warrior Jordan and he had decided to burn all the bridges that conn Ected the islands. This is a very cruel decision, but the Wizards of Jordan has advised him no to does so, because after that he own armies Would not being able to get from one island to another. So-Jordan decided to burn as many bridges as possible so that's was-still possible for he armies to get from any island to any other one.
Now the poor people of Ferry kingdom wonder what bridges would be burned. Of course, they cannot learn, because the list of bridges to be burned are kept in great secret. However, one old man said so can help them to find the set of bridges that certainly would not be burned.
So they came to you and asked. Can do?
Input
The input contains multiple test cases. The first line of the input was a single integer t (1 <= t <=) which is the number of the test cases. T test Cases Follow, each preceded to a single blank line.
The first line of all case contains N and m-the number of islands and bridges in Ferry Kingdom respectively (2 <= N <=, 1 <= M <= 100 000). Next M lines contain the different integer numbers each and describe bridges. Note that there can is several bridges between a pair of islands.
Output
On the first line of all case print k-the number of bridges that would certainly not be burned. On the second line print K integers-the numbers of these bridges. Bridges is numbered starting from one, as they is given in the input.
The consecutive cases should is separated by a and blank line. No blank line should is produced after the last Test case.
Sample Input
26 71 22 32 45 41 34 53 610 162 63 76 55 95 41 29 86 42 103 87 91 42 410 51 66 10
Sample Output
Main topic:
Give an 1~n graph, enter n (for n fixed point,), M (M edge, with heavy edge), (2 <= n <=, 1 <= m <= 100 000), the bridge in this graph is called, and the output bridge belongs to the ID of the input side.
Tarjin Template title:
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #define MAXN 10000+10 #define MAXM 200000+10using namespace Std;int N, m;int low[maxn];int dfn[maxn];int HEAD[MAXN], cnt;int dfs_clock;int num;/ /records There are several bridge int cutnum[maxm];//storage Bridge number struct Node {int u, V, again, id, next;}; Node Edge[maxm];void init () {cnt = 0; Memset (Head,-1, sizeof (head));} void Add (int u, int v, int id) {int i; for (i = head[u]; I! = 1; i = edge[i].next) {if (edge[i].v = = v) {break; }} if (i! =-1) edge[i].again = 1; else{edge[cnt] = {u, V, 0, id, head[u]}; Head[u] = cnt++; }}void Getmap () {for (int i = 1; I <= m; ++i) {int u, v; scanf ("%d%d", &u, &v); Add (U, V, i); Add (V, u, i); }}void Tarjan (int u, int fa) {Low[u] = dfn[u] = ++dfs_clock; for (int i = head[u]; i =-1; i = edge[i].next) {int v = EDGE[I].V; if (v = = FA) continue; if (!dfn[v]) {Tarjan (V, u); Low[u] = min (Low[u], low[v]); if (Low[v] > dfn[u] && edge[i].again = = 0) {cutnum[num++] = edge[i].id; }} else Low[u] = min (Low[u], dfn[v]); }}void find () {memset (DFN, 0, sizeof (DFN)); memset (Low, 0, sizeof (low)); num = 0; Dfs_clock = 0; Tarjan (1,-1);} void Solve () {printf ("%d\n", num); if (num = = 0) return; Sort (cutnum, cutnum + num); for (int i = 0; i < num; ++i) {if (!i) printf ("%d", cutnum[i]); else printf ("%d", cutnum[i]); } printf ("\ n");} int main () {int T; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n, &m); Init (); Getmap (); Find (); Solve (); if (T) printf ("\ n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ZOJ 2588--burning Bridges "non-lateral graph side Double unicom && output Bridge number"