Submission #531035

# Submission time Handle Problem Language Result Execution time Memory
531035 2022-02-27T12:49:05 Z Yazan_Alattar Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
8 ms 5068 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 1007;
const ll inf = 2e9;
const ll mod = 1e6 + 7;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

stack <int> st;
vector <int> adj[M];
int n, m, v[M], u[M], lis[M][M];
bool vist[M], onstack[M];

void dfs(int node, int p){
	vist[node] = 1; onstack[node] = 1;
	st.push(node);
	
	for(auto i : adj[node]) if(i != p){
		if(onstack[i]){
			while(st.top() != i) cout << v[st.top()] << " ", st.pop();
			cout << v[i] << endl;
			exit(0);
		}
		else if(!vist[i]) dfs(i, node);
	}
	
	onstack[node] = 0;
	st.pop();
	return;
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i){
		int a, b;
		scanf("%d%d", &a, &b);
		v[2 * i] = a; u[2 * i] = b;
		v[2 * i + 1] = b; u[2 * i + 1] = a;
		lis[a][b] = 2 * i; lis[b][a] = 2 * i + 1;
	}
	
	for(int i = 1; i <= 2 * m; ++i)
		for(int j = 1; j <= n; ++j)
			if(lis[u[i]][j] && j != v[i] && !lis[v[i]][j]) 
				adj[i].pb(lis[u[i]][j]);
	
	for(int i = 1; i <= 2 * m; ++i) if(!vist[i]) dfs(i, 0);
	cout << "no\n";
	return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
indcyc.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 716 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 716 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Incorrect 1 ms 1388 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1356 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1996 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 5068 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1996 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -