Submission #575871

# Submission time Handle Problem Language Result Execution time Memory
575871 2022-06-11T12:38:37 Z onebit1024 Game (APIO22_game) C++17
0 / 100
0 ms 208 KB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"




vector<vector<int>> adj,trans;

void dfs(vector<int>&order, int u,vector<bool>&visited){
  visited[u] = 1;
  for(int v : adj[u]){
    if(!visited[v])dfs(order, v, visited);
  }
  order.pb(u);
}

void SCC(vector<int>&scc, int u, vector<bool>&visited){
  visited[u] = 1;
  scc.pb(u);
  
  for(int v : trans[u]){
    if(!visited[v])SCC(scc, v, visited);
  }
}

int N;
int K;
void init(int n, int k) {
    adj.resize(n);
    trans.resize(n);
    N = n;
    K = k;
    for(int i = 0;i<=k-2;++i){
      adj[i].pb(i+1);
      trans[i+1].pb(i);
    }
}


int add_teleporter(int u, int v) {
  adj[u].pb(v);
  trans[v].pb(u);
  vector<int>order;
  vector<bool>visited(N);
  for(int i = 0;i<N;++i){
    if(!visited[i]){
      dfs(order, i, visited);
    }
  }
  visited.clear();
  visited = vector<bool>(N);
  for(int i = (int)(order.size()-1);i>=0;--i){
    if(!visited[order[i]]){
      vector<int>scc;
      SCC(scc, order[i], visited);
      if(scc.size() > 1){
        for(auto x : scc){

          if(x<K){
            return 1;
          }
        }
      }
    }
    
  }
  return 0;
}
// int32_t main(){
//   init(6,3);
//   add_teleporter(3,4);
//   add_teleporter(5, 0);
//   add_teleporter(4, 5);
//   add_teleporter(5, 3);
//   add_teleporter(1, 4);

//   // init(4,2);
//   // add_teleporter(1,1);
// }
/*
edge case 
init(6,3);
  add_teleporter(5,4);
  add_teleporter(4,3);
  add_teleporter(3,2);
  */
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -