Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #pragma comment(linker, "/stack:64000000")
- #include <string>
- #include <vector>
- #include <map>
- #include <list>
- #include <iterator>
- #include <cassert>
- #include <set>
- #include <queue>
- #include <iostream>
- #include <sstream>
- #include <stack>
- #include <deque>
- #include <cmath>
- #include <memory.h>
- #include <cstdlib>
- #include <cstdio>
- #include <cctype>
- #include <algorithm>
- #include <utility>
- #include <time.h>
- #include <complex>
- using namespace std;
- #define FOR(i, a, b) for(int i=(a);i<(b);i++)
- #define RFOR(i, b, a) for(int i=(b)-1;i>=(a);--i)
- #define FILL(A,value) memset(A,value,sizeof(A))
- #define ALL(V) V.begin(), V.end()
- #define SZ(V) (int)V.size()
- #define PB push_back
- #define MP make_pair
- #define Pi 3.14159265358979
- #define x0 ikjnrmthklmnt
- #define y0 lkrjhkltr
- #define y1 ewrgrg
- typedef long long Int;
- typedef unsigned long long UInt;
- typedef vector<int> VI;
- typedef pair<int, int> PII;
- typedef pair<Int, Int> PLL;
- typedef pair<double, double> PDD;
- typedef complex<double> base;
- const int INF = 1000000000;
- const int BASE = 1000000007;
- const int MAX = 200007;
- const int MAXV = 100007;
- const int MAXE = 100000;
- const int ADD = 1000000;
- const int MOD = 1000000007;
- const int CNT = 800;
- vector<PII> X[MAX];
- vector<PII> Y[MAX];
- VI G[MAX];
- bool U[MAX];
- int sum;
- int d[MAX];
- bool R[MAX];
- int tin[MAX];
- int fup[MAX];
- int timer = 0;
- int n;
- int UU[MAX];
- int dfs2(int v)
- {
- UU[v] = 1;
- int ret = 1;
- FOR(i,0,SZ(G[v]))
- {
- int to = G[v][i];
- if (UU[to]) continue;
- ret += dfs2(to);
- }
- return ret;
- }
- int comp;
- void dfs(int v , int p)
- {
- tin[v] = timer ++;
- U[v] = 1;
- fup[v] = tin[v];
- d[v] = 1;
- int dup = 0;
- FOR(i,0,SZ(G[v]))
- {
- int to = G[v][i];
- if (to == p) continue;
- if (U[to])
- {
- fup[v] = min(fup[v] , tin[to]);
- }
- else
- {
- dfs(to, v);
- d[v] += d[to];
- fup[v] = min(fup[v] , fup[to]);
- if (fup[to] >= tin[v])
- {
- if (d[to] % 2 == 1) R[v] = 0;
- }
- else
- {
- dup += d[to];
- }
- }
- }
- dup += comp - d[v];
- if (dup % 2 == 1) R[v] = 0;
- }
- int main()
- {
- //freopen("in.txt", "r", stdin);
- //freopen("distance.in", "r", stdin);
- //freopen("distance.out", "w", stdout);
- //freopen("out.txt" , "w" , stdout);
- cin >> n;
- vector<PII> A;
- FOR(i,0,2 * n + 1)
- {
- int x , y;
- scanf("%d%d" , &x , &y);
- X[x].push_back(MP(y , i));
- Y[y].push_back(MP(x , i));
- }
- FOR(i,0,MAX)
- {
- sort(ALL(X[i]));
- FOR(j,0,SZ(X[i]) - 1)
- {
- G[X[i][j].second].push_back(X[i][j + 1].second);
- G[X[i][j + 1].second].push_back(X[i][j].second);
- }
- FOR(j,0,SZ(X[i]) - 2)
- {
- G[X[i][j + 2].second].push_back(X[i][j].second);
- G[X[i][j].second].push_back(X[i][j + 2].second);
- }
- }
- FOR(i,0,MAX)
- {
- sort(ALL(Y[i]));
- FOR(j,0,SZ(Y[i]) - 1)
- {
- G[Y[i][j + 1].second].push_back(Y[i][j].second);
- G[Y[i][j].second].push_back(Y[i][j + 1].second);
- }
- FOR(j,0,SZ(Y[i]) - 2)
- {
- G[Y[i][j + 2].second].push_back(Y[i][j].second);
- G[Y[i][j].second].push_back(Y[i][j + 2].second);
- }
- }
- FOR(i,0,2 * n + 1)
- {
- R[i] = 1;
- }
- int cnt = 0;
- FOR(i,0,2 * n + 1)
- {
- if (U[i]) continue;
- comp = dfs2(i);
- dfs(i , -1);
- if (comp % 2 == 1) ++ cnt;
- }
- if (cnt > 1)
- {
- FOR(i,0,2 * n + 1)
- R[i] = 0;
- }
- FOR(i,0,2 * n + 1)
- {
- if (R[i]) printf("OK\n");
- else printf("NG\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement