#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mp make_pair
#define mid (l+r)/2
#define le node * 2
#define ri node * 2 + 1
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef pair<double,ll>pdi;
const ll inf=1e18;
const ll mod=998244353;
const ld Pi=acos(-1) ;
int n , m ;
vi v [1009] , ans ;
int done [1009] , in [1009] , go [1009][1009] ;
void dfs ( int node , int p ) {
ans .pb ( node ) ;
in [node] = 1 ;
for ( int i = (int) ans . size () - 3 ; i >= 0 ; i -- ) {
if ( go [ans[i]][node] ) {
for ( int j = i ; j < ans . size () ; j ++ ) {
cout << ans [j] + 1 << " " ;
}
cout << endl ;
exit (0) ;
}
}
for ( auto u : v [node] ) {
if ( u == p ) C ;
if ( p != -1 && go [u][p] ) C ;
dfs ( u , node ) ;
}
in [node] = 0 ;
ans .pop_back () ;
}
int main () {
cin >> n >> m ;
for ( int i = 0 ; i < m ; i ++ ) {
int a , b ;
cin >> a >> b ;
a -- , b -- ;
v [a] .pb ( b ) ;
v [b] .pb ( a ) ;
go [a][b] = go [b][a] = 1 ;
}
for ( int i = 0 ; i < n ; i ++ ) {
dfs ( 0 , -1 ) ;
}
cout << "no" << endl ;
}
Compilation message
indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:43:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for ( int j = i ; j < ans . size () ; j ++ ) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
18 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1055 ms |
1696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1536 KB |
Output is correct |
2 |
Correct |
796 ms |
1656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
4856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
4608 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
4728 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
300 ms |
3192 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |