답안 #1041653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041653 2024-08-02T06:46:01 Z 김은성(#11000) Brought Down the Grading Server? (CEOI23_balance) C++17
35 / 100
54 ms 19872 KB
#include <bits/stdc++.h>
using namespace std;
int n, s, t, *a[100009];
vector<pair<int, int> > graph[100009];
int ans[100009];
int deg[100009];	//out - in;
int cur[100009];
bool ch[100009];
void findcycle(int v){
	for(int i = cur[v]; i<graph[v].size(); i++){
		if(i < cur[v])
			i = cur[v];
		if(i == graph[v].size())
			break;
		auto [idx, u] = graph[v][i];
		cur[v]++;
		if(ans[idx] != -1)
			continue;
		ans[idx] = v;
		deg[v]++;
		deg[u]--;
		findcycle(u);
	}
}
void findpath(int v){
	ch[v]= 1;
	for(int i = 0; i<graph[v].size(); i++){
		auto [idx, u] = graph[v][i];
		if(ans[idx] != -1)
			continue;
		ans[idx] = v;
		deg[v]++;
		deg[u]--;
		if(ch[u] || graph[u].size()%2 == 0){
			findpath(u);
			break;
		}
		else{
			ch[u] = 1;
			break;
		}
	}
}
int main(){
	int i, j;
	scanf("%d %d %d", &n, &s, &t);
	memset(ans, -1, sizeof(ans));
	for(i=0; i<n; i++){
		a[i] = (int*)malloc(s * sizeof(int));
		for(j=0; j<s; j++){
			scanf("%d", &a[i][j]);
		}
		graph[a[i][0]].push_back(make_pair(i, a[i][1]));
		graph[a[i][1]].push_back(make_pair(i, a[i][0]));
	}
	for(i=1; i<=t; i++){
		if(graph[i].size()%2 == 1 && !ch[i])
			findpath(i), ch[i]=1;
	}
	memset(cur, 0, sizeof(cur));
	for(i=1; i<=t; i++){
		findcycle(i);
	}
	for(i=1; i<=t; i++){
		assert(-1 <= deg[i] && deg[i] <= 1);
	}
	for(i=0; i<n; i++){
		printf("%d %d\n", ans[i], a[i][0] + a[i][1] - ans[i]);
	}
	return 0;
}

Compilation message

balance.cpp: In function 'void findcycle(int)':
balance.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = cur[v]; i<graph[v].size(); i++){
      |                      ~^~~~~~~~~~~~~~~~
balance.cpp:13:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   if(i == graph[v].size())
      |      ~~^~~~~~~~~~~~~~~~~~
balance.cpp: In function 'void findpath(int)':
balance.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i = 0; i<graph[v].size(); i++){
      |                 ~^~~~~~~~~~~~~~~~
balance.cpp: In function 'int main()':
balance.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d %d %d", &n, &s, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
balance.cpp:51:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |    scanf("%d", &a[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Correct
2 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 1 ms 4444 KB Correct
3 Correct 1 ms 4524 KB Correct
4 Correct 1 ms 4444 KB Correct
5 Correct 1 ms 4444 KB Correct
6 Correct 1 ms 4444 KB Correct
7 Correct 1 ms 4444 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 19376 KB Correct
2 Correct 35 ms 19144 KB Correct
3 Correct 33 ms 17620 KB Correct
4 Correct 24 ms 17600 KB Correct
5 Correct 35 ms 19016 KB Correct
6 Correct 41 ms 19628 KB Correct
7 Correct 38 ms 12120 KB Correct
8 Correct 39 ms 19872 KB Correct
9 Correct 35 ms 19796 KB Correct
10 Correct 32 ms 19848 KB Correct
11 Correct 33 ms 19804 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 19376 KB Correct
2 Correct 35 ms 19144 KB Correct
3 Correct 33 ms 17620 KB Correct
4 Correct 24 ms 17600 KB Correct
5 Correct 35 ms 19016 KB Correct
6 Correct 41 ms 19628 KB Correct
7 Correct 38 ms 12120 KB Correct
8 Correct 39 ms 19872 KB Correct
9 Correct 35 ms 19796 KB Correct
10 Correct 32 ms 19848 KB Correct
11 Correct 33 ms 19804 KB Correct
12 Correct 40 ms 19280 KB Correct
13 Correct 36 ms 19148 KB Correct
14 Correct 37 ms 17676 KB Correct
15 Correct 26 ms 17344 KB Correct
16 Correct 34 ms 18884 KB Correct
17 Correct 45 ms 19740 KB Correct
18 Correct 34 ms 12124 KB Correct
19 Correct 42 ms 19792 KB Correct
20 Correct 41 ms 19856 KB Correct
21 Correct 30 ms 19792 KB Correct
22 Correct 33 ms 19800 KB Correct
23 Correct 40 ms 12280 KB Correct
24 Correct 31 ms 17760 KB Correct
25 Correct 48 ms 12284 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Correct
2 Correct 1 ms 4444 KB Correct
3 Correct 1 ms 4524 KB Correct
4 Correct 1 ms 4444 KB Correct
5 Correct 1 ms 4444 KB Correct
6 Correct 1 ms 4444 KB Correct
7 Correct 1 ms 4444 KB Correct
8 Correct 38 ms 19376 KB Correct
9 Correct 35 ms 19144 KB Correct
10 Correct 33 ms 17620 KB Correct
11 Correct 24 ms 17600 KB Correct
12 Correct 35 ms 19016 KB Correct
13 Correct 41 ms 19628 KB Correct
14 Correct 38 ms 12120 KB Correct
15 Correct 39 ms 19872 KB Correct
16 Correct 35 ms 19796 KB Correct
17 Correct 32 ms 19848 KB Correct
18 Correct 33 ms 19804 KB Correct
19 Correct 40 ms 19280 KB Correct
20 Correct 36 ms 19148 KB Correct
21 Correct 37 ms 17676 KB Correct
22 Correct 26 ms 17344 KB Correct
23 Correct 34 ms 18884 KB Correct
24 Correct 45 ms 19740 KB Correct
25 Correct 34 ms 12124 KB Correct
26 Correct 42 ms 19792 KB Correct
27 Correct 41 ms 19856 KB Correct
28 Correct 30 ms 19792 KB Correct
29 Correct 33 ms 19800 KB Correct
30 Correct 40 ms 12280 KB Correct
31 Correct 31 ms 17760 KB Correct
32 Correct 48 ms 12284 KB Correct
33 Correct 1 ms 4444 KB Correct
34 Correct 1 ms 4444 KB Correct
35 Correct 1 ms 4444 KB Correct
36 Correct 1 ms 4440 KB Correct
37 Correct 1 ms 4444 KB Correct
38 Correct 1 ms 4444 KB Correct
39 Correct 1 ms 4444 KB Correct
40 Correct 54 ms 19472 KB Correct
41 Correct 40 ms 19080 KB Correct
42 Correct 38 ms 17704 KB Correct
43 Correct 45 ms 17340 KB Correct
44 Correct 48 ms 18996 KB Correct
45 Correct 44 ms 19600 KB Correct
46 Correct 38 ms 12120 KB Correct
47 Correct 35 ms 19804 KB Correct
48 Correct 39 ms 19796 KB Correct
49 Correct 34 ms 19804 KB Correct
50 Correct 31 ms 19824 KB Correct
51 Correct 49 ms 12280 KB Correct
52 Correct 26 ms 17756 KB Correct
53 Correct 37 ms 12304 KB Correct
54 Correct 20 ms 8796 KB Correct
55 Correct 2 ms 4696 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 19376 KB Correct
2 Correct 35 ms 19144 KB Correct
3 Correct 33 ms 17620 KB Correct
4 Correct 24 ms 17600 KB Correct
5 Correct 35 ms 19016 KB Correct
6 Correct 41 ms 19628 KB Correct
7 Correct 38 ms 12120 KB Correct
8 Correct 39 ms 19872 KB Correct
9 Correct 35 ms 19796 KB Correct
10 Correct 32 ms 19848 KB Correct
11 Correct 33 ms 19804 KB Correct
12 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 19376 KB Correct
2 Correct 35 ms 19144 KB Correct
3 Correct 33 ms 17620 KB Correct
4 Correct 24 ms 17600 KB Correct
5 Correct 35 ms 19016 KB Correct
6 Correct 41 ms 19628 KB Correct
7 Correct 38 ms 12120 KB Correct
8 Correct 39 ms 19872 KB Correct
9 Correct 35 ms 19796 KB Correct
10 Correct 32 ms 19848 KB Correct
11 Correct 33 ms 19804 KB Correct
12 Correct 40 ms 19280 KB Correct
13 Correct 36 ms 19148 KB Correct
14 Correct 37 ms 17676 KB Correct
15 Correct 26 ms 17344 KB Correct
16 Correct 34 ms 18884 KB Correct
17 Correct 45 ms 19740 KB Correct
18 Correct 34 ms 12124 KB Correct
19 Correct 42 ms 19792 KB Correct
20 Correct 41 ms 19856 KB Correct
21 Correct 30 ms 19792 KB Correct
22 Correct 33 ms 19800 KB Correct
23 Correct 40 ms 12280 KB Correct
24 Correct 31 ms 17760 KB Correct
25 Correct 48 ms 12284 KB Correct
26 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Correct
2 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -