Submission #874102

# Submission time Handle Problem Language Result Execution time Memory
874102 2023-11-16T09:15:57 Z theghostking1 Friend (IOI14_friend) C++17
Compilation error
0 ms 0 KB
#include "friend.h"

// Find out best sample

int findSample(int n,int confidence[],int host[],int protocol[]){
	bool istree = true;
	for (int i = 0; i<n; i++){
		if (protocol[i] != 0) istree = false;
	}
	if (istree){
		//root the tree
		//use stack to dfs
		stack<pair<int,pair<int,int>>> s;
		vector<bool> vis(n);
		vector<int> col(n);
		s.push({0,0,-1});
		while (!s.empty()){
			pair<int,int> a = s.top();
			s.pop();
			int node = a.first;
			int prev = a.second.second;
			int flag = a.second.first;
			col[node] = flag;
			vis[node] = true;
			for (auto u : adj[node]){
				if (u == prev) continue;
				s.push({u,{1-flag,node}});
			}
		}
		int one = 0;
		int zero = 0;
		for (int i = 0; i<n; i++){
			if (col[i] == 0){
				zero += confidence[i];
			}
			else{
				one += confidence[i];
			}
		}
		return max(one,zero);
	}
	return ans;
}

Compilation message

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:13:3: error: 'stack' was not declared in this scope
   13 |   stack<pair<int,pair<int,int>>> s;
      |   ^~~~~
friend.cpp:13:9: error: 'pair' was not declared in this scope
   13 |   stack<pair<int,pair<int,int>>> s;
      |         ^~~~
friend.cpp:13:14: error: expected primary-expression before 'int'
   13 |   stack<pair<int,pair<int,int>>> s;
      |              ^~~
friend.cpp:14:3: error: 'vector' was not declared in this scope
   14 |   vector<bool> vis(n);
      |   ^~~~~~
friend.cpp:14:10: error: expected primary-expression before 'bool'
   14 |   vector<bool> vis(n);
      |          ^~~~
friend.cpp:15:10: error: expected primary-expression before 'int'
   15 |   vector<int> col(n);
      |          ^~~
friend.cpp:16:3: error: 's' was not declared in this scope
   16 |   s.push({0,0,-1});
      |   ^
friend.cpp:18:9: error: expected primary-expression before 'int'
   18 |    pair<int,int> a = s.top();
      |         ^~~
friend.cpp:20:15: error: 'a' was not declared in this scope
   20 |    int node = a.first;
      |               ^
friend.cpp:23:4: error: 'col' was not declared in this scope
   23 |    col[node] = flag;
      |    ^~~
friend.cpp:24:4: error: 'vis' was not declared in this scope
   24 |    vis[node] = true;
      |    ^~~
friend.cpp:25:18: error: 'adj' was not declared in this scope
   25 |    for (auto u : adj[node]){
      |                  ^~~
friend.cpp:33:8: error: 'col' was not declared in this scope
   33 |    if (col[i] == 0){
      |        ^~~
friend.cpp:40:10: error: 'max' was not declared in this scope
   40 |   return max(one,zero);
      |          ^~~
friend.cpp:42:9: error: 'ans' was not declared in this scope
   42 |  return ans;
      |         ^~~