# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244426 | SomeoneUnknown | Potemkin cycle (CEOI15_indcyc) | C++14 | 26 ms | 2048 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, r;
scanf("%d %d", &n, &r);
int ved[n+1];
for(int i = 1; i <= n; ++i) ved[i] = 0; //unvisited
vector<int> adjlist[n+1];
for(int i = 0; i < r; ++i){
int a, b;
scanf("%d %d", &a, &b);
adjlist[a].push_back(b);
adjlist[b].push_back(a);
}
for(int i = 1; i <= n; ++i){
if(ved[i] != 0) continue;
ved[i] = -1; //root
queue<int> tovisit;
tovisit.push(i);
while(!tovisit.empty()){
int ving = tovisit.front();
tovisit.pop();
for(int j = 0; j < adjlist[ving].size(); ++j){
int nghbr = adjlist[ving][j];
if(ved[nghbr] == 0){
ved[nghbr] = ving;
tovisit.push(nghbr);
}else if(ved[ving] != nghbr && ved[ving] != ved[nghbr]){
stack<int> s;
queue<int> e;
//s.push(ving);
//e.push(nghbr);
int last;
int sptr = ving;
int eptr = nghbr;
while(sptr != eptr){
s.push(sptr);
sptr = ved[sptr];
if(sptr == eptr) break;
e.push(eptr);
last = eptr;
eptr = ved[eptr];
}
bool djoint = true;
for(int k = 0; k < adjlist[s.top()].size(); k++){
if(adjlist[s.top()][k] == last) djoint = false;
}
if(djoint)
printf("%d ", sptr);
while(!s.empty()){
printf("%d ", s.top());
s.pop();
}
while(!e.empty()){
printf("%d ", e.front());
e.pop();
}
return 0;
}
}
}
}
printf("no");
}
Compilation message (stderr)
# | 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... |