Submission #982794

# Submission time Handle Problem Language Result Execution time Memory
982794 2024-05-14T18:10:10 Z vjudge1 Game (APIO22_game) C++17
0 / 100
0 ms 344 KB
#include "game.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int K;
int N;
vector<int> mini;
vector<int> maxi;
vector<vector<int>> teapuntan;
vector<vector<int>> apuntas;
void init(int n, int k) {
  N=n;
  K=k;
  mini.resize( n, 1e9);
  maxi.resize(n, -1);
  teapuntan.resize(n);
  apuntas.resize(n);
} 

int add_teleporter(int u, int v) {
  if(u<K && v<K){
    if(u<v) return 1;
    return 0;
  }
   if(u<K){
      
      queue<int> q;
      q.push(v);
      while(!q.empty()){
        int x=q.front();
        q.pop();
        if(maxi[x]>u) continue;
        maxi[x]=u;
        if(maxi[x]>=mini[x]) return 1;
        for(int y: apuntas[x]){
          q.push(y);
        }

      }

   }
   else if(v<K){
      queue<int> q;
      q.push(u);
      while(!q.empty()){
        int x=q.front();
        q.pop();
        if(mini[x]<v) continue;
        mini[x]=v;
        if(maxi[x]>=mini[x]) return 1;
        for(int y:teapuntan[x]){
          q.push(y);
        }
      }
   }
   else{
    apuntas[u].pb(v);
    teapuntan[v].pb(u);
    queue<int> q;
    q.push(v);
    vector<bool> visited1 (N, false);
    while(!q.empty()){
      int x=q.front();
      q.pop();
      if(visited1[x]) continue;
      visited1[x]=1;
      if(maxi[x]>maxi[u]) continue;
      maxi[x]=maxi[u];
      if(maxi[x]>=mini[x]) return 1;
        for(int y: apuntas[x]){
          if(visited1[y]) continue;
          q.push(y);
        }

    }
    vector<bool> visited2 (N, 0);
    q.push(u);
     while(!q.empty()){
        int x=q.front();
        q.pop();
        if(visited2[x]) continue;
        visited2[x]=1;
        if(mini[x]<mini[v]) continue;
        mini[x]=mini[v];
        if(maxi[x]>=mini[x]) return 1;
        for(int y:teapuntan[x]){
          if(visited2[y]) continue;
          q.push(y);
        }
      }
   }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer[1]
2 Halted 0 ms 0 KB -