#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
namespace output {
void pr(int x) {
cout << x;
}
void pr(long x) {
cout << x;
}
void pr(ll x) {
cout << x;
}
void pr(unsigned x) {
cout << x;
}
void pr(unsigned long x) {
cout << x;
}
void pr(unsigned long long x) {
cout << x;
}
void pr(float x) {
cout << x;
}
void pr(double x) {
cout << x;
}
void pr(long double x) {
cout << x;
}
void pr(char x) {
cout << x;
}
void pr(const char * x) {
cout << x;
}
void pr(const string & x) {
cout << x;
}
void pr(bool x) {
pr(x ? "true" : "false");
}
template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
template < class T > void pr(const T & x);
template < class T, class...Ts > void pr(const T & t,
const Ts & ...ts) {
pr(t);
pr(ts...);
}
template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
pr("{", x.f, ", ", x.s, "}");
}
template < class T > void pr(const T & x) {
pr("{"); // const iterator needed for vector<bool>
bool fst = 1;
for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
pr("}");
}
void ps() {
pr("\n");
} // print w/ spaces
template < class T, class...Ts > void ps(const T & t,
const Ts & ...ts) {
pr(t);
if (sizeof...(ts)) pr(" ");
ps(ts...);
}
void pc() {
cout << "]" << endl;
} // debug w/ commas
template < class T, class...Ts > void pc(const T & t,
const Ts & ...ts) {
pr(t);
if (sizeof...(ts)) pr(", ");
pc(ts...);
}
#define dbg(x...) pr("[", #x, "] = ["), pc(x);
}
#ifndef ONLINE_JUDGE
using namespace output;
#else
using namespace output;
#define dbg(x...)
#endif
const int MX = 2000;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;
int n, m;
int inc(int u, int v) {
return MX * u + v;
}
bool neg[1000][1000];
vi fin[MX * MX];
bool vis[MX * MX];
bool done[MX * MX];
vector<pi> ed;
int anc[MX * MX];
bool found = false;
vi ret;
int cnt = 0;
void dfs(int v, int p) {
if (found) return;
vis[v] = true;
for (int to : fin[v]) {
if (found) return;
if (!done[to]) {
if (!found && vis[to]) {
found = true;
int curr = v;
// dbg(curr, to);
while(curr != to) {
// dbg(curr);
// dbg(curr/2000, curr % 2000);
ret.pb((curr % 2000) + 1);
curr = anc[curr];
}
// dbg(to / 2000, to % 2000);
// dbg(to);
ret.pb((to % 2000) + 1);
return;
} else {
anc[to] = v;
// dbg("GO", to/2000, to%2000);
dfs(to, v);
}
}
}
done[v] = true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
u--, v--;
neg[u][v] = true;
neg[v][u] = true;
ed.pb(mp(u, v));
ed.pb(mp(v, u));
}
vector<pi> nods;
for (int i = 0; i < sz(ed); i++) {
int u = ed[i].f, v = ed[i].s;
for (int j = 0; j < n; j++) {
// dbg(u, v, j, adj[v].count(j), adj[u].count(j));
if (j != u && j != v && neg[v][j] && !neg[u][j]) {
// dbg(u, v, v, j);
// ps(inc(u, v), inc(v, j));
fin[inc(u, v)].pb(inc(v, j));
nods.pb(mp(u, v));
nods.pb(mp(v, j));
}
}
}
for (auto &x : nods) {
// dbg(x.f, x.s);
// if (deg[inc(x.f, x.s)] != 0) continue;
if (found) break;
if (!done[inc(x.f, x.s)]) dfs(inc(x.f, x.s), -1);
}
if (!found) cout << "no" << '\n';
else {
/*
for (int i = 0; i < sz(ret) - 1; i++) {
assert(neg[ret[i] - 1][ret[i + 1] - 1]);
}
*/
for (int i = 0; i < sz(ret); i++) cout << ret[i] << " ";
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
94328 KB |
Output is correct |
2 |
Correct |
64 ms |
94328 KB |
Output is correct |
3 |
Correct |
64 ms |
94328 KB |
Output is correct |
4 |
Correct |
63 ms |
94328 KB |
Output is correct |
5 |
Correct |
63 ms |
94328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
94456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
94328 KB |
Output is correct |
2 |
Correct |
70 ms |
94328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
94584 KB |
Wrong adjacency |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
95640 KB |
Output is correct |
2 |
Correct |
69 ms |
96336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
98032 KB |
Output is correct |
2 |
Correct |
73 ms |
97008 KB |
Output is correct |
3 |
Correct |
98 ms |
104384 KB |
Output is correct |
4 |
Correct |
102 ms |
104896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
101988 KB |
Output is correct |
2 |
Correct |
87 ms |
104420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
175020 KB |
Output is correct |
2 |
Correct |
202 ms |
111820 KB |
Output is correct |
3 |
Correct |
548 ms |
174756 KB |
Output is correct |
4 |
Correct |
207 ms |
116440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
493 ms |
253640 KB |
Output is correct |
2 |
Correct |
565 ms |
277312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
98796 KB |
Output is correct |
2 |
Correct |
187 ms |
96880 KB |
Output is correct |
3 |
Execution timed out |
1088 ms |
406612 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |