#include <bits/stdc++.h>
#define int long long
using namespace std;
const int KMAX=1e5+5, AMAX=5e6+5;
int viz[KMAX], a[KMAX], b[KMAX], k;
vector<int> adj[AMAX];
set<int> p;
int get_other(int i, int x)
{
if(a[i]!=x)
return a[i];
return b[i];
}
void DFS(int x, int y, int nviz)
{
if(nviz==k)
{
p.insert(min(x, y));
return;
}
for(auto i:adj[x])
if(!viz[i])
{
viz[i]=1;
DFS(x, y+get_other(i, x), nviz+1);
viz[i]=0;
}
for(auto i:adj[y])
if(!viz[i])
{
viz[i]=1;
DFS(x+get_other(i, y), y, nviz+1);
viz[i]=0;
}
}
signed main()
{
cin>>k;
for(int i=1;i<=k;i++)
{
cin>>a[i]>>b[i];
adj[a[i]].push_back(i);
adj[b[i]].push_back(i);
}
if(k<=10)
{
for(int i=1;i<=k;i++)
{
viz[i]=1;
DFS(a[i], b[i], 1);
viz[i]=0;
}
cout<<p.size()<<'\n';
for(auto x:p)
cout<<x<<'\n';
}
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... |