Submission #3930199


Source Code Expand

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 200005

int n;
vector<int> g[N];
bool ap[N];
int ord[N], low[N];
int lb = 0;
int dfs(int v, int p) {
  ord[v] = low[v] = lb++;
  int c = 0;
  repe(w, g[v]) {
    if(w == p) continue;
    if(ord[w] == -1) {
      dfs(w, v);
      ++c;
      ap[v] |= (ord[v] <= low[w]);
      low[v] = min(low[v], low[w]);
    } else {
      low[v] = min(low[v], ord[w]);
    }
  }
  if(p == -1) {
    ap[v] = (c > 1);
  }
}

void articulation() {
  rep(i, n) {
    ap[i] = false;
  }
  rep(i, n) {
    ord[i] = low[i] = -1;
  }
  rep(i, n) {
    if(ord[i] != -1) continue;
    dfs(i, -1);
  }
}

bool ans[N];
int sz[N];
bool used[N];
vector<int> vv;
int dfs0(int v, int p) {
  used[v] = true;
  ans[v] = true;
  vv.push_back(v);
  sz[v] = 1;
  repe(w, g[v]) {
    if(w == p || used[w]) continue;
    int c = dfs0(w, v);
    if(ord[v] <= low[w] && ap[v] && (c % 2)) {
      ans[v] = false;
    }
    sz[v] += c;
  }
  return sz[v];
}

map<int, vector<int>> rx, ry;

int main() {
  cin >> n;
  n = 2*n + 1;
  rep(i, n) {
    int x, y; cin >> x >> y;
    rx[x].push_back(i);
    ry[y].push_back(i);
  }
  repe(p, rx) {
    vector<int> &vs = p.second;
    rep(k, vs.size()-(vs.size() <= 2)) {
      int i = vs[k], j = vs[(k+1)%vs.size()];
      g[i].push_back(j);
      g[j].push_back(i);
    }
  }
  repe(p, ry) {
    vector<int> &vs = p.second;
    rep(k, vs.size()-(vs.size() <= 2)) {
      int i = vs[k], j = vs[(k+1)%vs.size()];
      g[i].push_back(j);
      g[j].push_back(i);
    }
  }
  articulation();

  rep(i, n) ans[i] = true, used[i] = false;
  int odd = 0;
  rep(i ,n) {
    if(used[i]) continue;
    vv.clear();
    int r = dfs0(i, -1);
    if(r % 2) {
      ++odd;
    } else {
      repe(v, vv) {
        ans[v] = false;
      }
    }
  }
  if(odd > 1) {
    rep(i, n) ans[i] = false;
  }
  rep(i, n) {
    cout << (ans[i] ? "OK" : "NG") << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task D - みんな仲良し高橋君
User yaketake08
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3396 Byte
Status AC
Exec Time 894 ms
Memory 53496 KiB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 3
AC × 15
AC × 48
Set Name Test Cases
Sample example_0.txt, example_1.txt, example_2.txt
Subtask1 bone_bubun_0.txt, bone_bubun_1.txt, bone_bubun_2.txt, komakai_bubun_0.txt, komakai_bubun_1.txt, komakai_bubun_2.txt, maxrand_bubun_0.txt, maxrand_bubun_1.txt, random_bubun_0.txt, random_bubun_1.txt, smallrand_bubun_0.txt, smallrand_bubun_1.txt, smallrand_bubun_2.txt, square_bubun_0.txt, square_bubun_1.txt
All bone_0.txt, bone_1.txt, bone_2.txt, bone_bubun_0.txt, bone_bubun_1.txt, bone_bubun_2.txt, example_0.txt, example_1.txt, example_2.txt, handmade_0.txt, handmade_1.txt, handmade_2.txt, handmade_3.txt, komakai_0.txt, komakai_1.txt, komakai_2.txt, komakai_bubun_0.txt, komakai_bubun_1.txt, komakai_bubun_2.txt, maxrand_0.txt, maxrand_1.txt, maxrand_bubun_0.txt, maxrand_bubun_1.txt, random_0.txt, random_1.txt, random_bubun_0.txt, random_bubun_1.txt, renket_0.txt, renket_1.txt, smallrand_0.txt, smallrand_1.txt, smallrand_bubun_0.txt, smallrand_bubun_1.txt, smallrand_bubun_2.txt, square_0.txt, square_1.txt, square_bubun_0.txt, square_bubun_1.txt, supersmall_0.txt, supersmall_1.txt, threeren_0.txt, threeren_1.txt, treebase_0.txt, treebase_1.txt, treebase_2.txt, example_0.txt, example_1.txt, example_2.txt
Case Name Status Exec Time Memory
bone_0.txt AC 691 ms 39600 KiB
bone_1.txt AC 690 ms 39600 KiB
bone_2.txt AC 692 ms 39600 KiB
bone_bubun_0.txt AC 147 ms 16696 KiB
bone_bubun_1.txt AC 18 ms 7296 KiB
bone_bubun_2.txt AC 207 ms 20148 KiB
example_0.txt AC 4 ms 5888 KiB
example_1.txt AC 4 ms 5888 KiB
example_2.txt AC 3 ms 5888 KiB
handmade_0.txt AC 4 ms 5888 KiB
handmade_1.txt AC 3 ms 5888 KiB
handmade_2.txt AC 4 ms 5888 KiB
handmade_3.txt AC 3 ms 5888 KiB
komakai_0.txt AC 749 ms 45304 KiB
komakai_1.txt AC 780 ms 45044 KiB
komakai_2.txt AC 769 ms 46712 KiB
komakai_bubun_0.txt AC 718 ms 53112 KiB
komakai_bubun_1.txt AC 696 ms 53496 KiB
komakai_bubun_2.txt AC 695 ms 53496 KiB
maxrand_0.txt AC 894 ms 41600 KiB
maxrand_1.txt AC 891 ms 41600 KiB
maxrand_bubun_0.txt AC 693 ms 43128 KiB
maxrand_bubun_1.txt AC 707 ms 43252 KiB
random_0.txt AC 22 ms 7040 KiB
random_1.txt AC 451 ms 26752 KiB
random_bubun_0.txt AC 24 ms 7296 KiB
random_bubun_1.txt AC 171 ms 16636 KiB
renket_0.txt AC 738 ms 41076 KiB
renket_1.txt AC 793 ms 41080 KiB
smallrand_0.txt AC 4 ms 5888 KiB
smallrand_1.txt AC 4 ms 5888 KiB
smallrand_bubun_0.txt AC 4 ms 5888 KiB
smallrand_bubun_1.txt AC 4 ms 5888 KiB
smallrand_bubun_2.txt AC 4 ms 5888 KiB
square_0.txt AC 528 ms 32120 KiB
square_1.txt AC 536 ms 32372 KiB
square_bubun_0.txt AC 544 ms 32632 KiB
square_bubun_1.txt AC 372 ms 25980 KiB
supersmall_0.txt AC 4 ms 5888 KiB
supersmall_1.txt AC 4 ms 5888 KiB
threeren_0.txt AC 701 ms 35704 KiB
threeren_1.txt AC 715 ms 37756 KiB
treebase_0.txt AC 561 ms 33140 KiB
treebase_1.txt AC 114 ms 12416 KiB
treebase_2.txt AC 407 ms 26364 KiB