Submission #896937

# Submission time Handle Problem Language Result Execution time Memory
896937 2024-01-02T11:19:06 Z Litusiano Game (APIO22_game) C++17
Compilation error
0 ms 0 KB
dc++.h>
using namespace std;
#include "game.h"


int k1,n1;

vector<vector<int>> G,Grev, DAG;
vector<int> top,used,scc;
int act = 0;
void dfs(int u){
	if(used[u]) return;
	used[u] = 1;
	for(int v : G[u]) dfs(v);
	top.push_back(u);
}

void dfs1(int u){
	if(used[u]) return;
	used[u] = 1;
	for(int v : Grev[u]){
		dfs1(v);
	}
	scc[u] = act;
}

void init(int n, int k) {
	k1 = k; n1 = n;
	G.assign(n,vector<int>());
	Grev = G;
	for(int i = 0; i<k-1; i++){
		G[i].push_back(i+1);
		Grev[i+1].push_back(i);
	}
}

int add_teleporter(int u, int v) {
	G[u].push_back(v);
	Grev[v].push_back(u);
	used.assign(n1,0);
	scc.assign(n1,-1);
	top.clear();
	dfs(0);
	used.assign(n1,0);
	act = 0;
	for(int i = top.size()-1; i>=0; i--){
		if(!used[top[i]]) act++, scc[top[i]] = act, dfs1(top[i]);
	}
	set<int> hv; 
	for(int i = 0; i<k1; i++){
		hv.insert(scc[i]);
	}
	// // cerr<<"STARTING SCC OF EDGE: "<<u<<" "<<v<<endl;
	// for(int i = 0; i<n1; i++){
	// 	cerr<<"SCC: "<<i<<" "<<scc[i]<<endl;
	// }
	// cerr<<endl;
	if(hv.size() <k1) return 1;

	for(int i = k1; i<n1; i++){
		if(hv.count(scc[i])) return 1;
	}
  return 0;
}

Compilation message

game.cpp:1:1: error: 'dc' does not name a type
    1 | dc++.h>
      | ^~
game.cpp:8:1: error: 'vector' does not name a type
    8 | vector<vector<int>> G,Grev, DAG;
      | ^~~~~~
game.cpp:9:1: error: 'vector' does not name a type
    9 | vector<int> top,used,scc;
      | ^~~~~~
game.cpp: In function 'void dfs(int)':
game.cpp:12:5: error: 'used' was not declared in this scope
   12 |  if(used[u]) return;
      |     ^~~~
game.cpp:13:2: error: 'used' was not declared in this scope
   13 |  used[u] = 1;
      |  ^~~~
game.cpp:14:14: error: 'G' was not declared in this scope
   14 |  for(int v : G[u]) dfs(v);
      |              ^
game.cpp:15:2: error: 'top' was not declared in this scope
   15 |  top.push_back(u);
      |  ^~~
game.cpp: In function 'void dfs1(int)':
game.cpp:19:5: error: 'used' was not declared in this scope
   19 |  if(used[u]) return;
      |     ^~~~
game.cpp:20:2: error: 'used' was not declared in this scope
   20 |  used[u] = 1;
      |  ^~~~
game.cpp:21:14: error: 'Grev' was not declared in this scope
   21 |  for(int v : Grev[u]){
      |              ^~~~
game.cpp:24:2: error: 'scc' was not declared in this scope
   24 |  scc[u] = act;
      |  ^~~
game.cpp: In function 'void init(int, int)':
game.cpp:29:2: error: 'G' was not declared in this scope
   29 |  G.assign(n,vector<int>());
      |  ^
game.cpp:29:13: error: 'vector' was not declared in this scope
   29 |  G.assign(n,vector<int>());
      |             ^~~~~~
game.cpp:29:20: error: expected primary-expression before 'int'
   29 |  G.assign(n,vector<int>());
      |                    ^~~
game.cpp:30:2: error: 'Grev' was not declared in this scope
   30 |  Grev = G;
      |  ^~~~
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:38:2: error: 'G' was not declared in this scope
   38 |  G[u].push_back(v);
      |  ^
game.cpp:39:2: error: 'Grev' was not declared in this scope
   39 |  Grev[v].push_back(u);
      |  ^~~~
game.cpp:40:2: error: 'used' was not declared in this scope
   40 |  used.assign(n1,0);
      |  ^~~~
game.cpp:41:2: error: 'scc' was not declared in this scope
   41 |  scc.assign(n1,-1);
      |  ^~~
game.cpp:42:2: error: 'top' was not declared in this scope
   42 |  top.clear();
      |  ^~~
game.cpp:49:2: error: 'set' was not declared in this scope
   49 |  set<int> hv;
      |  ^~~
game.cpp:49:6: error: expected primary-expression before 'int'
   49 |  set<int> hv;
      |      ^~~
game.cpp:51:3: error: 'hv' was not declared in this scope; did you mean 'v'?
   51 |   hv.insert(scc[i]);
      |   ^~
      |   v
game.cpp:58:5: error: 'hv' was not declared in this scope; did you mean 'v'?
   58 |  if(hv.size() <k1) return 1;
      |     ^~
      |     v
game.cpp:61:6: error: 'hv' was not declared in this scope; did you mean 'v'?
   61 |   if(hv.count(scc[i])) return 1;
      |      ^~
      |      v