/**
* author: Haunted_Cpp
**/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
const int MAX_N = 5e3 + 5;
int g[MAX_N][MAX_N], dp[MAX_N][MAX_N], nxt[MAX_N][MAX_N];
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = (i == j ? 0 : 1e9);
nxt[i][j] = j;
}
}
for (int i = 0; i < m; i++) {
int st, et;
cin >> st >> et;
--st; --et;
g[st][et] = g[et][st] = 1;
dp[st][et] = dp[et][st] = 1;
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(dp[i][j] > dp[i][k] + dp[k][j]) {
dp[i][j] = dp[i][k] + dp[k][j];
nxt[i][j] = nxt[i][k];
}
}
}
}
auto get_path = [&](int source, int destination) {
vector<int> path;
while(source != destination) {
path.emplace_back(source);
source = nxt[source][destination];
}
return path;
};
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if (dp[i][j] > 1e7 || dp[j][j] > 1e7 || dp[k][i] > 1e7) continue;
vector<int> A = get_path(i, j);
vector<int> B = get_path(j, k);
vector<int> C = get_path(k, i);
vector<int> all;
for (auto to : A) all.emplace_back(to);
for (auto to : B) all.emplace_back(to);
for (auto to : C) all.emplace_back(to);
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
if (all.size() < 4) continue;
bool valid = true;
for (int cur = 0; cur < (int) all.size(); cur++) {
int cnt = 0;
for (int to = 0; to < (int) all.size(); to++) {
if (to == cur) continue;
cnt += (dp[all[cur]][all[to]] == 1);
}
valid &= (cnt == 2);
}
if (valid) {
for (auto to : all) cout << to + 1 << ' ';
cout << '\n';
return 0;
}
}
}
}
cout << "no" << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
488 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1664 KB |
Wrong adjacency |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
1784 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
4992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1095 ms |
4992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1047 ms |
24184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1039 ms |
23936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1080 ms |
7936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |