#include <bits/stdc++.h>
#define task "I"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1002, NN = 1e5 + 1;
int n, m, dep[NN << 1], par[NN << 1];
bool d[N][N], in[NN << 1];
vi g[N], gr[NN << 1];
ii edge[NN];
vi res;
void dfs(int u, int p)
{
in[u] = 1;
par[u] = p;
dep[u] = dep[p] + 1;
int mx = -1, mxi = 0;
for (int v : gr[u]) if (v != p)
{
if (!dep[v]) dfs(v, u);
else if (in[v] && mx < dep[v]) mx = dep[v], mxi = v;
}
if (res.empty() && mx != -1)
{
while (u != mxi)
{
int uu = u >> 1;
res.eb(edge[uu].F);
res.eb(edge[uu].S);
u = par[u];
}
res.eb(edge[mxi >> 1].F);
res.eb(edge[mxi >> 1].S);
}
in[u] = 0;
}
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n >> m;
rep(i, 0, m - 1)
{
int u, v;
cin >> u >> v;
g[u].eb(i);
g[v].eb(i);
d[u][v] = d[v][u] = 1;
edge[i] = {u, v};
}
rep(i, 0, m - 1)
{
int u = edge[i].F, v = edge[i].S;
for (int j : g[v]) if (j != i)
{
int id = (edge[j].F == v) ? (j << 1) : ((j << 1) | 1), w = (edge[j].F == v) ? edge[j].S : edge[j].F;
if (d[u][w]) continue;
gr[i << 1].eb(id);
}
for (int j : g[u]) if (j != i)
{
int id = (edge[j].F == u) ? (j << 1) : ((j << 1) | 1), w = (edge[j].F == u) ? edge[j].S : edge[j].F;
if (d[v][w]) continue;
gr[(i << 1) | 1].eb(id);
}
}
rep(i, 0, 2 * m - 1) if (!dep[i]) dfs(i, i);
if (res.empty())
{
cout << "no";
return 0;
}
for (int i = 2; i < SZ(res); i += 2) if (res[i] != res[i - 1]) swap(res[i], res[i + 1]);
for (int i = 0; i < SZ(res); i += 2) cout << res[i] << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
5120 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
5120 KB |
Repeated vertex |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5120 KB |
Output is correct |
2 |
Correct |
4 ms |
5120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
5248 KB |
Repeated vertex |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
5376 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
5760 KB |
Output is correct |
2 |
Correct |
7 ms |
5760 KB |
Output is correct |
3 |
Incorrect |
17 ms |
7808 KB |
Repeated vertex |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
6912 KB |
Output is correct |
2 |
Correct |
12 ms |
7040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
22684 KB |
Output is correct |
2 |
Incorrect |
34 ms |
9848 KB |
Repeated vertex |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
51092 KB |
Output is correct |
2 |
Correct |
154 ms |
55416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
9280 KB |
Output is correct |
2 |
Correct |
238 ms |
9720 KB |
Output is correct |
3 |
Incorrect |
337 ms |
91256 KB |
Repeated vertex |
4 |
Halted |
0 ms |
0 KB |
- |