#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;
vii adj[100005];
bool vis[100005];
int tv[100005];
int n,m,used;
bool dfs(int u, int p){
//cout << u << " " << used << endl;
tv[u] = 1;
for(auto x : adj[u])
{
if(x.fi == p)
continue;
if(vis[x.se])
continue;
//cout << tv[x.fi] << endl;
if(tv[x.fi]){
vis[x.se] = true;
used++;
tv[x.fi] = 2;
tv[u] = 0;
cout << u << " ";
return true;
}
vis[x.se] = true;
used++;
if(dfs(x.fi,u)){
cout << u << " ";
//cout << tv[u] << endl;
if(tv[u] == 2){
tv[u] = 0;
cout << endl;
continue;
}
return true;
}
vis[x.se] = 0;
used--;
}
return false;
}
int main(){
optimise;
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
int a,b;
cin >> a >>b;
adj[a].pb({b,i});
adj[b].pb({a,i});
}
int d = 1;
while (used != m)
{
for (int i = 1; i <= n; ++i)
{
memset(tv, 0, sizeof tv);
if(dfs(i,-1)){
break;
} else
d++;
}
//cout << tv[1] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Execution timed out |
1083 ms |
3020 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Execution timed out |
1093 ms |
3020 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
3020 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |