이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <limits.h>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <cstring>
#include <sstream>
#pragma GCC target("popcnt")
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
typedef pair<ll,ll>point;
//#define x first
//#define y second
int n,m;
unordered_set<int>nodes[1000];
void get_path(vector<int>& path,unordered_set<int>&path_set){
int node=path.back();
for(int next:nodes[node]){
// check for repetitions and connections
if(path_set.find(next)!=path_set.end())
continue;
bool rep=false;
for(int i=1;i<(int)path.size()-1;i++){
if(nodes[path[i]].find(next)!=nodes[path[i]].end()){
rep=true;
break;
}
}
if(rep)
continue;
if(path.size()>=3&&nodes[next].find(path[0])!=nodes[next].end()){
for(int i:path)
cout<<i+1<<" ";
cout<<next+1<<"\n";
exit(0);
}
if(path.size()>=2&&nodes[path[0]].find(next)!=nodes[path[0]].end())
continue;
path.push_back(next);
path_set.insert(next);
get_path(path,path_set);
path_set.erase(next);
path.pop_back();
}
}
int main(){
ios::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;b--;
nodes[a].insert(b);
nodes[b].insert(a);
}
for(int i=0;i<n;i++){
vector<int>path={i};
unordered_set<int>path_set={i};
get_path(path,path_set);
}
cout<<"no\n";
return 0;
}
/*
5 6
1 2
1 3
2 3
4 3
5 2
4 5
4 5
1 2
2 3
3 4
4 1
1 3
*/
# | 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... |