当前位置:网站首页>P1656 bombing Railway
P1656 bombing Railway
2022-07-03 23:46:00 【Statichit static smash】
Title Description
A The country sent a general uim, Yes B The United Nations undertakes strategic measures , In order to save the people who are painted with charcoal .
B State-owned nn Cities , These cities are connected by rail . Any two cities can be reached directly or indirectly by rail .
uim After discovering that some of the railways were destroyed , Two cities can't reach each other by rail . Such a railway is called key road.
uim In order to paralyze the country's logistics system as soon as possible , Hope to blow up the railway , In order to achieve the effect that two cities cannot reach each other by railway .
However , Only one shell (A The Congress won't give money ). therefore , Which railway can he bomb ?
Input format
first line nn,m (1 \leq n\leq 150m(1≤n≤150,1 \leq m \leq 5000)1≤m≤5000), They are nn Cities , in total mm A railway .
following mm That's ok , Two integers per line a, ba,b, Representing City aa And the city bb There's a direct rail connection between them .
Output format
The output has several lines .
Each line contains two numbers aa,bb, among a<ba<b, Express <a,b><a,b> yes key road.
Please note that : When the output , All number pairs <a,b><a,b> Must follow aa Sort output from small to large ; If aa identical , According to bb Sort from small to large .
I/o sample
Input #1 Copy
6 6 1 2 2 3 2 4 3 5 4 5 5 6Output #1 Copy
1 2 5 6
This question examines Cut edge of graph
The steps of edge cutting and point cutting of graph are almost the same , There is only one difference in the code implementation
I wrote in this blog about the cutting point and edge of graph
( Not yet I'll post the link after I write it )
This problem is a typical edge cutting template problem of graph , The train of thought is : Depth first traverses every point , Depth first traversal to point u when , Suppose there are vertices in the graph v It is a point that has not been visited , Judgment vertex v Can I go back to the point I visited before ( Including some u), The way to judge is : To the summit v Do another depth first traversal , But this traversal is not allowed to pass through vertices u, If vertex v You can't go back to your ancestors , There is no other way back u, that u-v This side is the cut side .
Another special feature of this question is the output time , All number pairs <a,b> Must follow a Sort output from small to large ; If a identical , According to b Sort from small to large . You need to store the edge cutting with a structure array , Then sort according to this rule .
ac Code
#include<bits/stdc++.h>
using namespace std;
#define N 160
int n,m,x,y;
int v[N][N];
int num[N],low[N],flag[N],dex,o;
struct
{
int x,y;
} ans[N];
void dfs(int cur,int father)
{
dex++;
num[cur]=dex;
low[cur]=dex;
for(int i=1; i<=n; i++)
{
if(v[cur][i] == 1)
{
if(num[i] == 0)
{
dfs(i,cur);
low[cur]=min(low[i],low[cur]);
if(low[i]>num[cur])
{
ans[o].x=cur;
ans[o].y=i;
o++;
}
}
else if(i != father)
{
low[cur]=min(low[cur],num[i]);
}
}
}
}
int main()
{
cin>>n>>m;
while(m--)
{
cin>>x>>y;
v[x][y]=1;
v[y][x]=1;
}
int root=1;
dfs(1,root);
/// Sort
for(int i=0; i<o-1; i++)
for(int j=i+1; j<o; j++)
{
if(ans[j].x<ans[i].x)
{
int temp=ans[j].x;ans[j].x=ans[i].x;ans[i].x=temp;
temp=ans[j].y;ans[j].y=ans[i].y;ans[i].y=temp;
}
else if(ans[j].x == ans[i].x)
{
if(ans[j].y<ans[i].y)
{
int temp=ans[j].x;ans[j].x=ans[i].x;ans[i].x=temp;
temp=ans[j].y;ans[j].y=ans[i].y;ans[i].y=temp;
}
}
}
for(int i=0; i<o; i++)
cout<<ans[i].x<<" "<<ans[i].y<<endl;
return 0;
}
边栏推荐
- Current detection circuit - including op amp current scheme
- Arc135 partial solution
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Interpretation of corolla sub low configuration, three cylinder power configuration, CVT fuel saving and smooth, safety configuration is in place
- Iclr2022: how does AI recognize "things I haven't seen"?
- Unsafe and CAS principle
- The interviewer's biggest lie to deceive you, bypassing three years of less struggle
- Scratch uses runner Py run or debug crawler
- D28:maximum sum (maximum sum, translation)
- Interesting 10 CMD commands
猜你喜欢

Idea set class header comments

I wrote a chat software with timeout connect function

X Opencv feature point detection and matching

Investment demand and income forecast report of China's building ceramics industry, 2022-2028
![Docking Alipay process [pay in person, QR code Payment]](/img/30/665580241020ee3adb872e725f0624.jpg)
Docking Alipay process [pay in person, QR code Payment]

Hcip day 16 notes

Apple released a supplementary update to MacOS Catalina 10.15.5, which mainly fixes security vulnerabilities

2022 t elevator repair registration examination and the latest analysis of T elevator repair

How to write a good title of 10w+?

2022 system integration project management engineer examination knowledge points: software development model
随机推荐
I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
2022.02.14
股票开户最低佣金炒股开户免费,网上开户安全吗
[MySQL] classification of multi table queries
Pyqt5 sensitive word detection tool production, operator's Gospel
炒股开户佣金优惠怎么才能获得,网上开户安全吗
How to make icons easily
C # basic knowledge (3)
[MySQL] sql99 syntax to realize multi table query
Selenium library 4.5.0 keyword explanation (I)
A treasure open source software, cross platform terminal artifact tabby
Tencent interview: can you pour water?
Hcip 13th day notes
在恒泰证券开户怎么样?安全吗?
Comment obtenir une commission préférentielle pour l'ouverture d'un compte en bourse? Est - ce que l'ouverture d'un compte en ligne est sécurisée?
Version rollback revert don't reset better reset must be forced
Research Report on the scale prediction of China's municipal engineering industry and the prospect of the 14th five year plan 2022-2028
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Loop compensation - explanation and calculation of first-order, second-order and op amp compensation
Alibaba cloud container service differentiation SLO hybrid technology practice