#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define fi first
#define se second
#define INF 1e7
#define unsigned u
#define eps 1e-18
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAX_A 100005
#define V 450
#define re register
#define maxi(a,b) ((a) > (b) ? (a) : (b))
using namespace std;
set<int> adj[2005];
bool vis[2005][2005];
int n,m,used;
bool dfs(int u, int p, int start){
//cout << u << " " << start << " " << used << endl;
for(auto x : adj[u])
{
//cout << adj[u].size() << endl;
if(x == p)
continue;
if(vis[u][x])
continue;
vis[u][x] = true;
vis[x][u] = true;
used++;
if(x == start)
{
if(used == m)
return true;
for (int i = 1; i <= n; ++i)
{
//cout << i << endl;
//memset(vis, 0, sizeof vis);
if(dfs(i,-1,i)){
cout << i << endl;
return true;
}
}
vis[u][x] = 0;
vis[x][u] = 0;
used--;
return false;
}
if(dfs(x,u,start)){
cout << x << " ";
return true;
}
vis[u][x] = false;
vis[x][u] = false;
used--;
}
return false;
}
int main(){
optimise;
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
int a,b;
cin >> a >>b;
adj[a].insert(b);
adj[b].insert(a);
}
for (int i = 1; i <= n; ++i)
{
used = 0;
if(dfs(i,-1,i)){
cout << i;
return 0;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Same junction appears twice in a route |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Same junction appears twice in a route |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Same junction appears twice in a route |
3 |
Halted |
0 ms |
0 KB |
- |