Submission #21269641


Source Code Expand

#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = 3.14159265359;
const ll INF = 1LL << 60;

int n;

int node(int i, bool b)
{
  return i + (b ? n : 0);
}

int main()
{
  int d;
  cin >> n >> d;

  vector<ll> x(n);
  vector<ll> y(n);
  for (int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }

  scc_graph g(n*2);

  for (int i = 0; i < n; i++){
    for (int j = i + 1; j < n; j++){
      if (abs(x[i] - x[j]) < d){
	g.add_edge(node(i, true), node(j, false));
	g.add_edge(node(j, true), node(i, false));
      }
      if (abs(y[i] - x[j]) < d){
	g.add_edge(node(i, false), node(j, false));
	g.add_edge(node(j, true), node(i, true));
      }
      if (abs(x[i] - y[j]) < d){
	g.add_edge(node(i, true), node(j, true));
	g.add_edge(node(j, false), node(i, false));
      }
      if (abs(y[i] - y[j]) < d){
	g.add_edge(node(i, false), node(j, true));
	g.add_edge(node(j, false), node(i, true));
      }
    }
  }

  auto v = g.scc();
  vector<int> scc(n*2);
  for (int i = 0; i < v.size(); i++){
    for (int x : v[i]){
      scc[x] = i;
    }
  }

  for (int i = 0; i < n; i++){
    if (scc[node(i, true)] == scc[node(i, false)]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (int i = 0; i < n; i++){
    if (scc[node(i, true)] > scc[node(i, false)])
      cout << x[i] << endl;
    else
      cout << y[i] << endl;
  }
  
  return 0;
}

Submission Info

Submission Time
Task H - Two SAT
User unnohideyuki
Language C++ (GCC 9.2.1)
Score 100
Code Size 1533 Byte
Status AC
Exec Time 14 ms
Memory 3772 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:52:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::vector<int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   52 |   for (int i = 0; i < v.size(); i++){
      |                   ~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 23
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 8 ms 3440 KiB
00-sample-02.txt AC 10 ms 3448 KiB
01-01.txt AC 2 ms 3508 KiB
01-02.txt AC 9 ms 3768 KiB
01-03.txt AC 5 ms 3536 KiB
01-04.txt AC 5 ms 3672 KiB
01-05.txt AC 13 ms 3656 KiB
01-06.txt AC 5 ms 3568 KiB
01-07.txt AC 2 ms 3484 KiB
01-08.txt AC 11 ms 3528 KiB
01-09.txt AC 7 ms 3668 KiB
01-10.txt AC 2 ms 3504 KiB
01-11.txt AC 6 ms 3740 KiB
01-12.txt AC 10 ms 3680 KiB
01-13.txt AC 8 ms 3680 KiB
01-14.txt AC 11 ms 3676 KiB
01-15.txt AC 10 ms 3712 KiB
01-16.txt AC 9 ms 3772 KiB
01-17.txt AC 9 ms 3720 KiB
01-18.txt AC 14 ms 3756 KiB
01-19.txt AC 7 ms 3756 KiB
01-20.txt AC 9 ms 3768 KiB
01-21.txt AC 8 ms 3760 KiB