Submission #586334

#TimeUsernameProblemLanguageResultExecution timeMemory
586334SeDunionFriend (IOI14_friend)C++17
Compilation error
0 ms0 KiB
#include "friend.h"
#include<iostream>
#include<assert.h>
#include<vector>
 
using namespace std;
 
const int N = 1e6 + 123;
 
vector<int>g[N];
int c[N];
 
int used[N];
 #include "friend.h"
#include<iostream>
#include<assert.h>
#include<vector>
 
using namespace std;
 
const int N = 1e6 + 123;
 
vector<int>g[N];
int c[N];
 
int used[N];
 
void dfs(int v, int &a, int &b) {
	a += c[v];
	used[v] = 1;
	for (int to : g[v]) if (!used[to]) {
		dfs(to, b, a);
	}
}
 
int findSample(int n,int confidence[],int host[],int protocol[]){
	for (int i = 0 ; i < n ; ++ i) {
		c[i] = confidence[i];
	}
	for (int i = 1 ; i < n ; ++ i) {
		int j = host[i];
		g[j].emplace_back(i);
		g[i].emplace_back(j);
	}
	int a = 0, b = 0;
	dfs(0, a, b);
	return max(a, b);
}
void dfs(int v, int &a, int &b) {
	a += c[v];
	used[v] = 1;
	for (int to : g[v]) if (!used[to]) {
		dfs(to, b, a);
	}
}
 
int findSample(int n,int confidence[],int host[],int protocol[]){
	for (int i = 1 ; i < n ; ++ i) {
		assert(host[i] < i);
	}
	for (int i = 0 ; i < n ; ++ i) {
		c[i] = confidence[i];
	}
	for (int i = 1 ; i < n ; ++ i) {
		int j = host[i];
		g[j].emplace_back(i);
		g[i].emplace_back(j);
	}
	int a = 0, b = 0;
	dfs(0, a, b);
	return max(a, b);
}

Compilation message (stderr)

friend.cpp:21:11: error: redefinition of 'const int N'
   21 | const int N = 1e6 + 123;
      |           ^
friend.cpp:8:11: note: 'const int N' previously defined here
    8 | const int N = 1e6 + 123;
      |           ^
friend.cpp:23:12: error: redefinition of 'std::vector<int> g [1000123]'
   23 | vector<int>g[N];
      |            ^
friend.cpp:10:12: note: 'std::vector<int> g [1000123]' previously declared here
   10 | vector<int>g[N];
      |            ^
friend.cpp:24:5: error: redefinition of 'int c [1000123]'
   24 | int c[N];
      |     ^
friend.cpp:11:5: note: 'int c [1000123]' previously declared here
   11 | int c[N];
      |     ^
friend.cpp:26:5: error: redefinition of 'int used [1000123]'
   26 | int used[N];
      |     ^~~~
friend.cpp:13:5: note: 'int used [1000123]' previously declared here
   13 | int used[N];
      |     ^~~~
friend.cpp:49:6: error: redefinition of 'void dfs(int, int&, int&)'
   49 | void dfs(int v, int &a, int &b) {
      |      ^~~
friend.cpp:28:6: note: 'void dfs(int, int&, int&)' previously defined here
   28 | void dfs(int v, int &a, int &b) {
      |      ^~~
friend.cpp:57:5: error: redefinition of 'int findSample(int, int*, int*, int*)'
   57 | int findSample(int n,int confidence[],int host[],int protocol[]){
      |     ^~~~~~~~~~
friend.cpp:36:5: note: 'int findSample(int, int*, int*, int*)' previously defined here
   36 | int findSample(int n,int confidence[],int host[],int protocol[]){
      |     ^~~~~~~~~~