답안 #54784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54784 2018-07-05T05:26:34 Z 2등은 나의 것^^(#2060) Potemkin cycle (CEOI15_indcyc) C++11
10 / 100
256 ms 15340 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
vector<int>edge[1212];
int depth[1212], is_gone_dfs1[1212];
set<pair<int, int>>L[1212];  set<int>M[1212];
void dfs1(int w,int dep,int bef) {
	depth[w] = dep; is_gone_dfs1[w] = 1;
	for (int i = 0; i < edge[w].size(); i++) {
		int next = edge[w][i];
		if (is_gone_dfs1[next]) {
			if(next==bef || depth[next] > depth[w])continue;
			L[w].insert({ depth[next],next });
			continue;
		}
		dfs1(next, dep + 1, w);
	}
}
int stdep, D[1212], st;
int dfs2(int w, int bef) {
	set<pair<int, int>>::iterator it = L[w].lower_bound({stdep + 1,-1e9});
	if (bef != -1 && it == L[w].end())D[w] = D[bef] + 1;
	if (bef != -1 && it != L[w].end())D[w] = D[it->second] + 1;
	if (D[w] >= 4 && M[w].find(st) != M[w].end()) { printf("%d ", w); return 1; }
	if (M[w].find(st) != M[w].end())D[w] = 2;
	for (int i = 0; i < edge[w].size(); i++) {
		int next = edge[w][i];
		if (depth[next] - depth[w] != 1)continue;
		if (dfs2(next, w)) { printf("%d ", w); return 1; }
	}
	return 0;
}
int main() {
	int n, m; scanf("%d%d", &n, &m);
	int i, j;
	for (i = 0; i < m; i++) {
		int s, e; scanf("%d%d", &s, &e);
		edge[s].push_back(e); M[s].insert(e);
		edge[e].push_back(s); M[e].insert(s);
	}
	for (i = 1; i <= n; i++) {
		if (is_gone_dfs1[i])continue;
		dfs1(i, 1, -1);
	}
	for (i = 1; i <= n; i++) {
		D[i] = 1; st = i; stdep = depth[i];
		if (dfs2(i, -1)) return 0;
		for (j = 1; j <= n; j++)D[j] = 0;
	}
	printf("no");
	return 0;
}

Compilation message

indcyc.cpp: In function 'void dfs1(int, int, int)':
indcyc.cpp:11:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < edge[w].size(); i++) {
                  ~~^~~~~~~~~~~~~~~~
indcyc.cpp: In function 'int dfs2(int, int)':
indcyc.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < edge[w].size(); i++) {
                  ~~^~~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:36:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, m; scanf("%d%d", &n, &m);
            ~~~~~^~~~~~~~~~~~~~~~
indcyc.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int s, e; scanf("%d%d", &s, &e);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Wrong adjacency
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 660 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 784 KB Wrong adjacency
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 792 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1176 KB Output is correct
2 Incorrect 5 ms 1200 KB Wrong adjacency
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1200 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 208 ms 8172 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 8172 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 15228 KB Output is correct
2 Correct 256 ms 15340 KB Output is correct
3 Incorrect 120 ms 15340 KB Wrong adjacency
4 Halted 0 ms 0 KB -