#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int n,m;
struct date
{
char a;
short x;
};
vector<vector<date>> muchii;
bool use[100005];
int topar[100005],par[100005];
int niv[100005],nivmin[100005];
date getdata(int x)
{
date rez;
rez.x=x%(1<<15);
rez.a=(x>>14);
return rez;
}
int getnum(date x)
{
int rez=x.x+x.a*(1<<15);
return rez;
}
void dfs(int nod)
{
use[nod]=1;
nivmin[nod]=niv[nod];
for(date i:muchii[nod])
{
int node=getnum(i);
if(node==par[nod])
continue;
if(!use[node])
{
par[node]=nod;
niv[node]=niv[nod]+1;
dfs(node);
nivmin[nod]=min(nivmin[nod],nivmin[node]);
}
else
nivmin[nod]=min(nivmin[nod],niv[node]);
}
int cnt=0;
if(nivmin[nod]==niv[nod]&&par[nod]!=0)
{
for(date i:muchii[nod])
{
int x=getnum(i);
if(x==par[nod])
cnt++;
}
if(cnt==1)
cout<<par[nod]<<' '<<nod<<'\n';
}
}
bool comp(date a, date b)
{
return getnum(a)<getnum(b);
}
int main()
{
cin>>n>>m;
muchii.resize(n+1);
for(int i=1;i<=m;i++)
{
int a,b;
cin>>a>>b;
muchii[a].push_back(getdata(b));
muchii[b].push_back(getdata(a));
}
for(int i=1;i<=n;i++)
sort(muchii[i].begin(),muchii[i].end(),comp);
for(int i=1;i<=n;i++)
if(!use[i])
{
niv[i]=1;
dfs(i);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1020 KB |
Output is correct |
2 |
Correct |
7 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
341 ms |
8644 KB |
Output is correct |
2 |
Correct |
352 ms |
7900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
567 ms |
12496 KB |
Output is correct |
2 |
Runtime error |
774 ms |
16648 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1000 ms |
46592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1327 ms |
54724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2167 ms |
65536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2952 ms |
65536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3650 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3686 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |