#include <bits/stdc++.h>
#define DIM 1010
#define DIMBUFF 7000000
#define INF 2000000000
using namespace std;
//FILE *fin = fopen ("date.in","r");
//FILE *fout = fopen ("date.out","w");
FILE *fin = stdin;
FILE *fout = stdout;
vector <int> L[DIM];
int dist[DIM],t[DIM],a[DIM][DIM],c[DIM],sol[DIM];
pair <int,int> mch[DIM*DIM];
int n,m,x,y,i,j,k,ok,pos,el;
char buff[DIMBUFF];
int bfs (int start){
for (int i=1;i<=n;i++){
dist[i] = INF;
t[i] = 0;
}
int p = 1, u = 0;
c[++u] = start;
dist[start] = 0;
int ok = 0, val;
while (p <= u){
int nod = c[p];
p++;
for (auto vecin : L[nod]){
if (dist[vecin] == INF && a[nod][vecin]){
dist[vecin] = 1 + dist[nod];
t[vecin] = nod;
if (a[vecin][x]){
if (dist[vecin] > 1){
val = vecin;
while (val){
fprintf(fout,"%d ",val);
val = t[val];
}
return 1;
}
} else c[++u] = vecin;
}}}
return 0;
}
int get_nr(){
while(!(buff[pos] >= '0' && buff[pos] <= '9'))
pos++;
int nr = 0;
while (buff[pos] >= '0' && buff[pos] <= '9'){
nr = nr*10 + buff[pos] - '0';
pos++;
}
return nr;
}
int main (){
fread (buff,1,DIMBUFF,fin);
//cin>>n>>m;
n = get_nr(), m = get_nr();
for (i=1;i<=m;++i){
//cin>>x>>y;
x = get_nr(), y = get_nr();
L[x].push_back(y);
L[y].push_back(x);
a[x][y] = a[y][x] = 1;
mch[i] = make_pair (x,y);
}
for (i=1;i<=m;i++){
x = mch[i].first, y = mch[i].second;
a[x][y] = a[y][x] = 0;
if (bfs(y)){ /// am gasit un drum ok
fprintf(fout,"%d ",x);
return 0;
}
a[x][y] = a[y][x] = 1;
}
fprintf(fout,"no");
return 0;
}
Compilation message
indcyc.cpp: In function 'int bfs(int)':
indcyc.cpp:26:9: warning: unused variable 'ok' [-Wunused-variable]
int ok = 0, val;
^~
indcyc.cpp: In function 'int main()':
indcyc.cpp:65:11: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
fread (buff,1,DIMBUFF,fin);
~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1664 KB |
Output is correct |
2 |
Correct |
5 ms |
1664 KB |
Output is correct |
3 |
Correct |
6 ms |
1920 KB |
Output is correct |
4 |
Correct |
37 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1664 KB |
Output is correct |
2 |
Correct |
7 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
5632 KB |
Output is correct |
2 |
Correct |
31 ms |
4992 KB |
Output is correct |
3 |
Execution timed out |
1095 ms |
5632 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
4864 KB |
Output is correct |
2 |
Correct |
34 ms |
4864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
4608 KB |
Output is correct |
2 |
Correct |
210 ms |
4608 KB |
Output is correct |
3 |
Correct |
154 ms |
6016 KB |
Output is correct |
4 |
Execution timed out |
1097 ms |
6016 KB |
Time limit exceeded |