// Restart
// += O(logn) ; + = O(n)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz size()
#define FORN(i,j,n) for(int i=j; i<(int)n;i++)
#define FOR(i,n) FORN(i,0,n)
#define FORIT(i,x) for( auto i = x.begin() ; i != x.end() ; i++ )
#define MOD 998244353LL
#define MOD1 1000000007LL
#define LIM 262150
#define ones(x) __builtin_popcount(x)
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y,z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define INF 1000000000
#define in(x) cin>>x;
#define out(x) cout<<x;
#define MAXIMO 1LL<<60
#define loga2(x) __builtin_ctzll(x)
//SOLO PARA POTENCIAS DE 2
using namespace std;
using namespace __gnu_pbds;
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int,ii> iii;
typedef vector <string> vs;
typedef vector <ii> vii;
typedef vector <iii> viii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int n,r;
bool M[1001][1001] = {0};
vii E;
vii G[1001];
bool vis[200002] ={0};
vi G2[200002];
stack<int> ans;
void dfs(int start){
if(vis[start]){
//trace3(ans.top(), E[ans.top()].fst , E[ans.top()].snd)
cout<<E[ans.top()].fst; ans.pop();
while(ans.top() != start){
//trace3(ans.top(), E[ans.top()].fst , E[ans.top()].snd)
cout<<" "<<E[ans.top()].fst; ans.pop();
}
//trace3(ans.top(), E[ans.top()].fst , E[ans.top()].snd)
cout<<" "<<E[ans.top()].fst<<"\n";
exit(0);
}
vis[start] = true;
ans.push(start);
for (auto v : G2[start]) {
dfs(v);
}
ans.pop();
vis[start] = false;
}
void go(){
cin>>n>>r;
E.pb({-1,-1}); // JUST FOR INDEX
for(int i=1;i<=r;i++){
int x, y ; cin>>x>>y;
M[x][y] = M[y][x] = true;
E.pb({x,y});
E.pb({y,x});
G[x].pb({y,2*i-1});
G[y].pb({x,2*i});
}
for(int i=1; i<E.size() ; i++){
int &v = E[i].fst ; int &u = E[i].snd;
for(auto it2: G[u]){
if(it2.fst != v && !M[it2.fst][v]){
//trace2(i, it2.snd)
G2[i].pb(it2.snd);
}
}
}
for(int i=1; i<E.size() ; i++){
dfs(i);
}
cout<<"no\n";
}
void timer(){
clock_t begin = clock();
go();
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
cout<<time_spent<<"\n";
}
int main() {
//fastio;
go();
//timer();
return 0;
}
Compilation message
indcyc.cpp: In function 'void go()':
indcyc.cpp:95:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int i=1; i<E.size() ; i++){
| ~^~~~~~~~~
indcyc.cpp:106:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i=1; i<E.size() ; i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
4 ms |
5032 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
5032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
5024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5324 KB |
Output is correct |
2 |
Correct |
8 ms |
5428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
5708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6860 KB |
Output is correct |
2 |
Correct |
168 ms |
7000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
23068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
51256 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
55372 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
9960 KB |
Output is correct |
2 |
Correct |
215 ms |
9828 KB |
Output is correct |
3 |
Correct |
240 ms |
91324 KB |
Output is correct |
4 |
Execution timed out |
1084 ms |
91320 KB |
Time limit exceeded |