#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
int n, m;
vector<int> way[1004];
int chk[1004], ss, from[1004], did[1004], didN;
int que[1004], f, r;
void bfs(int s, int e){
f = r = 0;
que[r++] = s;
did[s] = didN;
while(f < r){
int now = que[f]; ++f;
for(auto&nxt:way[now]){
if(nxt != e && (!chk[nxt] || did[nxt] == didN)) continue;
from[nxt] = now;
que[r++] = nxt;
did[nxt] = didN;
}
}
if(did[e] == didN){
int now = e;
while(true){
cout << now << ' ';
if(now == s) break;
now = from[now];
}
cout << ss << '\n';
exit(0);
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
map<pair<int, int>, int> cant;
for(int i = 1; i <= m; ++i){
int x, y; cin >> x >> y;
if(x > y) swap(x, y);
way[x].push_back(y);
way[y].push_back(x);
cant[{x, y}] = 1;
}
for(int i = 1; i <= n; ++i) chk[i] = 1;
for(int i = 1; i <= n; ++i){
chk[i] = 0;
sort(way[i].begin(), way[i].end());
for(auto&nxt:way[i]){
chk[nxt] = 0;
}
ss = i;
for(int j = 0; j < (int)way[i].size(); ++j){
for(int k = j + 1; k < (int)way[i].size(); ++k){
if(cant[{way[i][j], way[i][k]}]) continue;
++didN;
bfs(way[i][j], way[i][k]);
}
}
chk[i] = 1;
for(auto&nxt:way[i]){
chk[nxt] = 1;
}
}
cout << "no\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
34752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
48800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
736 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
4 |
Correct |
75 ms |
1636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
54748 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1091 ms |
41304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
83 ms |
4312 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
296 ms |
7332 KB |
Output is correct |
2 |
Execution timed out |
1093 ms |
7300 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |