답안 #575869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575869 2022-06-11T12:34:27 Z onebit1024 게임 (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"

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

void print(){cerr << endl;};
template <typename T, typename... Args>
void print(T one, Args... rest){
    cerr << one << " ";
    print(rest...);
}


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);
}



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);
    }
}

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 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);
  */
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -