이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int n,m;
struct date
{
bitset<2> 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[0]=((x>>15)&1);
rez.a[1]=((x>>16)&1);
return rez;
}
int getnum(date x)
{
int rez=x.x+x.a[0]*(1<<15)+x.a[1]*(1<<16);
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |