Submission #983513

# Submission time Handle Problem Language Result Execution time Memory
983513 2024-05-15T15:25:47 Z Alkaser_ID Game (APIO22_game) C++17
Compilation error
0 ms 0 KB
#include "game.h"
using namespace std;
#include <bits/stdc++.h>
const sz = 1e6 = 5;

int res = 0,K=0;
set<int> scc[sz], rv[sz];
int c[sz]; bool b[sz];
void init(int n, int k) {
    K = k;
    for(int i=0;i<k;++i){
        b[i] = true;
        c[i] = i;
        if(i < k-1) {
            scc[i].insert(i+1);
        }
    }
    for(int i=k;i<n;++i) c[i] = i;
}

bool vis[sz]; set<int> s; int sp = 0;
vector<int> cv;
inline void cycle() {
    int C = *s.begin();
    set<int>::iterator it = s.begin();
    for(++it;it!=s.end();++it){
        for(set<int>::iterator j = scc[*it].begin();j != scc[*it].end();++j){
            scc[C].insert(*j);
            rv[*j].insert(C);
        }
        c[*it] = C;
        for(set<int>::iterator jt = rv[*it].begin();jt != rv[*it].end();++jt){
            scc[*jt].erase(*it);
            scc[*jt].insert(C);
        }
    }
    b[C] = (sp > 0);
    if(b[C]) res = 1;
}
inline void dfs(int i, int rt){
    s.insert(i); if(i <K) ++sp;
    vis[i] = true;
    cv.push_back(i);
    for(set<int>::iterator j=scc[i].begin();j!=scc[i].end();++j){
        if(*j == rt && !s.empty()) {
            cycle(); s.clear();
            return;
        }
        if(s.empty()) return;
        if(!vis[*j]) dfs(*j,rt);
    }
    if(s.empty()) return;
    s.erase(i); if(i < K) --sp;
}

int add_teleporter(int u, int v) {
    if(u == v) res = 1;
    if(c[u] == c[v] || res == 1) return res;
    scc[c[u]].insert(c[v]);
    rv[c[v]].insert(c[u]);
    dfs(c[u],c[u]);
    for(int j=0;j<cv.size();++j) {
        vis[cv[j]] = false;
    }
    cv.clear();
    return res;
}

/*
6 5 3
3 4
5 0
4 5
5 3
1 4

4 1 2
1 1

4 3 2
1 3
2 0
3 2

*/

Compilation message

game.cpp:4:7: error: 'sz' does not name a type
    4 | const sz = 1e6 = 5;
      |       ^~
game.cpp:7:14: error: 'sz' was not declared in this scope
    7 | set<int> scc[sz], rv[sz];
      |              ^~
game.cpp:7:22: error: 'sz' was not declared in this scope
    7 | set<int> scc[sz], rv[sz];
      |                      ^~
game.cpp:8:7: error: 'sz' was not declared in this scope
    8 | int c[sz]; bool b[sz];
      |       ^~
game.cpp:8:19: error: 'sz' was not declared in this scope
    8 | int c[sz]; bool b[sz];
      |                   ^~
game.cpp: In function 'void init(int, int)':
game.cpp:12:9: error: 'b' was not declared in this scope
   12 |         b[i] = true;
      |         ^
game.cpp:13:9: error: 'c' was not declared in this scope
   13 |         c[i] = i;
      |         ^
game.cpp:15:13: error: 'scc' was not declared in this scope
   15 |             scc[i].insert(i+1);
      |             ^~~
game.cpp:18:26: error: 'c' was not declared in this scope
   18 |     for(int i=k;i<n;++i) c[i] = i;
      |                          ^
game.cpp: At global scope:
game.cpp:21:10: error: 'sz' was not declared in this scope
   21 | bool vis[sz]; set<int> s; int sp = 0;
      |          ^~
game.cpp: In function 'void cycle()':
game.cpp:27:36: error: 'scc' was not declared in this scope
   27 |         for(set<int>::iterator j = scc[*it].begin();j != scc[*it].end();++j){
      |                                    ^~~
game.cpp:29:13: error: 'rv' was not declared in this scope; did you mean 'cv'?
   29 |             rv[*j].insert(C);
      |             ^~
      |             cv
game.cpp:31:9: error: 'c' was not declared in this scope
   31 |         c[*it] = C;
      |         ^
game.cpp:32:37: error: 'rv' was not declared in this scope; did you mean 'cv'?
   32 |         for(set<int>::iterator jt = rv[*it].begin();jt != rv[*it].end();++jt){
      |                                     ^~
      |                                     cv
game.cpp:33:13: error: 'scc' was not declared in this scope
   33 |             scc[*jt].erase(*it);
      |             ^~~
game.cpp:37:5: error: 'b' was not declared in this scope
   37 |     b[C] = (sp > 0);
      |     ^
game.cpp: In function 'void dfs(int, int)':
game.cpp:42:5: error: 'vis' was not declared in this scope
   42 |     vis[i] = true;
      |     ^~~
game.cpp:44:30: error: 'scc' was not declared in this scope
   44 |     for(set<int>::iterator j=scc[i].begin();j!=scc[i].end();++j){
      |                              ^~~
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:58:8: error: 'c' was not declared in this scope
   58 |     if(c[u] == c[v] || res == 1) return res;
      |        ^
game.cpp:59:5: error: 'scc' was not declared in this scope
   59 |     scc[c[u]].insert(c[v]);
      |     ^~~
game.cpp:59:9: error: 'c' was not declared in this scope
   59 |     scc[c[u]].insert(c[v]);
      |         ^
game.cpp:60:5: error: 'rv' was not declared in this scope; did you mean 'v'?
   60 |     rv[c[v]].insert(c[u]);
      |     ^~
      |     v
game.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int j=0;j<cv.size();++j) {
      |                 ~^~~~~~~~~~
game.cpp:63:9: error: 'vis' was not declared in this scope
   63 |         vis[cv[j]] = false;
      |         ^~~