이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> wgraf;
typedef pair<int,ii> edge;
typedef vector <ll> vl;
typedef pair <ll, ll> LL;
typedef vector <LL> vll;
#define UNVISITED 0
#define VISITED 1
#define pb push_back
#define F first
#define S second
ll n, m, u, v, visto[500005];
vll grafo[500005];
map <ll, bool> puede;
bool vale = false;
void dfs(ll origen, ll nodo, ll padre, ll aux) {
if (nodo == origen && padre != -1) {
vale = true;
return;
}
for (auto i : grafo[nodo]) {
if (i.F != padre && puede[i.S] == true && visto[i.F] != aux) {
puede[i.S] = false;
visto[i.F] = aux;
dfs(origen, i.F, nodo, aux);
if (vale == true) {
cout << nodo << " ";
return;
}
puede[i.S] = true;
}
}
}
void SOLVE(){
cin >> n >> m;
for (ll i = 0; i < n; i++) visto[i] = 0;
for (ll i = 0; i < m; i++){
cin >> u >> v;
grafo[u].pb({v, i});
grafo[v].pb({u, i});
puede[i] = true;
}
ll cnt = 0;
for (ll i = 1; i <= n; i++) {
vale = false;
cnt++;
dfs(i, i, -1, cnt);
if (vale == true) cout << "\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while(t--){
SOLVE();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |