이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, par[N];
bool is_edge[N][N], vis[N];
vector<int> g[N];
vector<pair<int, int>> edges;
void bfs(int id){
auto [x, y] = edges[id];
memset(vis, 0, sizeof vis);
memset(par, -1, sizeof par);
for (int z = 1; z <= n; z ++)
vis[z] = (is_edge[x][z] and is_edge[z][y]);
queue<int> q;
q.push(x);
vis[x] = 1;
while (!q.empty()){
int v = q.front();
q.pop();
for (int e : g[v]){
if (e == id) continue;
int u = edges[e].first + edges[e].second - v;
if (vis[u]) continue;
par[u] = v;
vis[u] = 1;
q.push(u);
}
}
}
int main(){
cin >> n >> m;
for (int e = 0; e < m; e ++){
int u, v;
cin >> u >> v;
edges.push_back({u, v});
g[u].push_back(e);
g[v].push_back(e);
is_edge[u][v] = is_edge[v][u] = 1;
}
for (int e = 0; e < m; e ++){
bfs(e);
auto [u, v] = edges[e];
if (vis[u] and vis[v]){
while (v != u){
cout << v << " ";
v = par[v];
}
cout << u << endl;
return 0;
}
}
cout << "no" << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |