답안 #531038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531038 2022-02-27T13:01:49 Z Yazan_Alattar Potemkin cycle (CEOI15_indcyc) C++14
100 / 100
481 ms 93088 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 int N = 200007;
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[N];
int n, m, v[N], u[N], lis[M][M];
bool vist[N], onstack[N];

void dfs(int node, int p){
	vist[node] = onstack[node] = 1;
	st.push(node);
	
	for(auto i : adj[node]) if(i != p && onstack[i]){
		while(st.top() != i) printf("%d ", v[st.top()]), st.pop();
		printf("%d ", v[i]);
		exit(0);
	}
	
	for(auto i : adj[node]) if(i != p && !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);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 2 ms 4940 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5580 KB Output is correct
2 Correct 5 ms 5648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6476 KB Output is correct
2 Correct 11 ms 6496 KB Output is correct
3 Correct 25 ms 8328 KB Output is correct
4 Correct 20 ms 8388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7636 KB Output is correct
2 Correct 12 ms 7772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 24688 KB Output is correct
2 Correct 78 ms 12360 KB Output is correct
3 Correct 266 ms 24996 KB Output is correct
4 Correct 76 ms 12356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 53728 KB Output is correct
2 Correct 151 ms 57808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 8768 KB Output is correct
2 Correct 159 ms 9444 KB Output is correct
3 Correct 450 ms 92952 KB Output is correct
4 Correct 481 ms 93088 KB Output is correct