Submission #1041628

# Submission time Handle Problem Language Result Execution time Memory
1041628 2024-08-02T06:29:15 Z 김은성(#11000) Brought Down the Grading Server? (CEOI23_balance) C++17
15 / 100
61 ms 22608 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;
	//printf("v=%d\n", 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]--;
		ch[u] = 1;
		if(graph[u].size()%2 == 0)
			findpath(u);
		else
			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);
	}
	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]);
	}
}

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:28: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]
   28 |  for(int i = cur[v]; i<graph[v].size(); i++){
      |                      ~^~~~~~~~~~~~~~~~
balance.cpp:31: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]
   31 |   if(i == graph[v].size())
      |      ~~^~~~~~~~~~~~~~~~~~
balance.cpp: In function 'int main()':
balance.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  scanf("%d %d %d", &n, &s, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
balance.cpp:54:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |    scanf("%d", &a[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Correct
2 Runtime error 4 ms 9020 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 19444 KB Correct
2 Correct 39 ms 19148 KB Correct
3 Correct 36 ms 17676 KB Correct
4 Correct 29 ms 17344 KB Correct
5 Correct 41 ms 18888 KB Correct
6 Correct 42 ms 19800 KB Correct
7 Correct 42 ms 12016 KB Correct
8 Correct 34 ms 19972 KB Correct
9 Correct 48 ms 19808 KB Correct
10 Correct 33 ms 19796 KB Correct
11 Correct 37 ms 19912 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 19444 KB Correct
2 Correct 39 ms 19148 KB Correct
3 Correct 36 ms 17676 KB Correct
4 Correct 29 ms 17344 KB Correct
5 Correct 41 ms 18888 KB Correct
6 Correct 42 ms 19800 KB Correct
7 Correct 42 ms 12016 KB Correct
8 Correct 34 ms 19972 KB Correct
9 Correct 48 ms 19808 KB Correct
10 Correct 33 ms 19796 KB Correct
11 Correct 37 ms 19912 KB Correct
12 Correct 49 ms 19320 KB Correct
13 Correct 38 ms 19060 KB Correct
14 Correct 56 ms 17664 KB Correct
15 Correct 44 ms 17336 KB Correct
16 Correct 61 ms 18888 KB Correct
17 Correct 43 ms 19792 KB Correct
18 Correct 36 ms 12116 KB Correct
19 Correct 39 ms 19796 KB Correct
20 Correct 39 ms 19796 KB Correct
21 Correct 32 ms 19800 KB Correct
22 Correct 59 ms 19796 KB Correct
23 Runtime error 36 ms 22608 KB Execution killed with signal 6
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Correct
2 Runtime error 4 ms 9020 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 19444 KB Correct
2 Correct 39 ms 19148 KB Correct
3 Correct 36 ms 17676 KB Correct
4 Correct 29 ms 17344 KB Correct
5 Correct 41 ms 18888 KB Correct
6 Correct 42 ms 19800 KB Correct
7 Correct 42 ms 12016 KB Correct
8 Correct 34 ms 19972 KB Correct
9 Correct 48 ms 19808 KB Correct
10 Correct 33 ms 19796 KB Correct
11 Correct 37 ms 19912 KB Correct
12 Incorrect 1 ms 4444 KB Unexpected end of file - int32 expected
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 19444 KB Correct
2 Correct 39 ms 19148 KB Correct
3 Correct 36 ms 17676 KB Correct
4 Correct 29 ms 17344 KB Correct
5 Correct 41 ms 18888 KB Correct
6 Correct 42 ms 19800 KB Correct
7 Correct 42 ms 12016 KB Correct
8 Correct 34 ms 19972 KB Correct
9 Correct 48 ms 19808 KB Correct
10 Correct 33 ms 19796 KB Correct
11 Correct 37 ms 19912 KB Correct
12 Correct 49 ms 19320 KB Correct
13 Correct 38 ms 19060 KB Correct
14 Correct 56 ms 17664 KB Correct
15 Correct 44 ms 17336 KB Correct
16 Correct 61 ms 18888 KB Correct
17 Correct 43 ms 19792 KB Correct
18 Correct 36 ms 12116 KB Correct
19 Correct 39 ms 19796 KB Correct
20 Correct 39 ms 19796 KB Correct
21 Correct 32 ms 19800 KB Correct
22 Correct 59 ms 19796 KB Correct
23 Runtime error 36 ms 22608 KB Execution killed with signal 6
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -