Submission #2549667


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >

vector< T > shortest_path_faster_algorithm(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);
  vector< int > pending(g.size(), 0), times(g.size(), 0);
  queue< int > que;

  que.emplace(s);
  pending[s] = true;
  ++times[s];
  dist[s] = 0;

  while(!que.empty()) {
    int p = que.front();
    que.pop();
    pending[p] = false;
    for(auto &e : g[p]) {
      T next_cost = dist[p] + e.cost;
      if(next_cost >= dist[e.to]) continue;
      dist[e.to] = next_cost;
      if(!pending[e.to]) {
        if(++times[e.to] >= g.size()) return vector< T >();
        pending[e.to] = true;
        que.emplace(e.to);
      }
    }
  }
  return dist;
}


int main() {
  int N, M;
  int P[1000], Q[1000];

  scanf("%d %d", &N, &M);
  for(int i = 0; i < N; i++) {
    scanf("%d", &P[i]);
  }
  for(int i = 0; i < N; i++) {
    scanf("%d", &Q[i]);
  }
  WeightedGraph< int > g(2 * N + 1);
  int S = 2 * N;
  for(int i = 0; i < N; i++) {
    g[i].emplace_back(S, 0);
    g[S].emplace_back(i, P[i]);
    g[S].emplace_back(N + i, 0);
    g[N + i].emplace_back(S, Q[i]);
  }
  for(int i = 0; i < M; i++) {
    int x, y, a, b;
    scanf("%d %d %d %d", &x, &y, &a, &b);
    --x, --y;
    g[x].emplace_back(N + y, -a);
    g[N + y].emplace_back(x, b);
  }
  auto ret = shortest_path_faster_algorithm(g, S);
  if(ret.empty() || ret[S] < 0) puts("no");
  else puts("yes");
}

Submission Info

Submission Time
Task H - Asteroids2
User ei13333
Language C++14 (GCC 5.4.1)
Score 200
Code Size 2115 Byte
Status AC
Exec Time 345 ms
Memory 5632 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:66:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &M);
                         ^
./Main.cpp:68:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &P[i]);
                       ^
./Main.cpp:71:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q[i]);
                       ^
./Main.cpp:83:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &x, &y, &a, &b);
                                         ^

Judge Result

Set Name All
Score / Max Score 200 / 200
Status
AC × 41
Set Name Test Cases
All 00-sample-00, 00-sample-01, 10-small_yes-00, 10-small_yes-01, 10-small_yes-02, 10-small_yes-03, 10-small_yes-04, 10-small_yes-05, 10-small_yes-06, 10-small_yes-07, 10-small_yes-08, 20-small_disturb-00, 20-small_disturb-01, 20-small_disturb-02, 20-small_disturb-03, 20-small_disturb-04, 20-small_disturb-05, 20-small_disturb-06, 20-small_disturb-07, 20-small_disturb-08, 30-large_yes-00, 30-large_yes-01, 30-large_yes-02, 30-large_yes-03, 30-large_yes-04, 40-large_disturb-00, 40-large_disturb-01, 40-large_disturb-02, 40-large_disturb-03, 40-large_disturb-04, 40-large_disturb-05, 40-large_disturb-06, 40-large_disturb-07, 40-large_disturb-08, 40-large_disturb-09, 40-large_disturb-10, 40-large_disturb-11, 40-large_disturb-12, 40-large_disturb-13, 40-large_disturb-14, 40-large_disturb-15
Case Name Status Exec Time Memory
00-sample-00 AC 1 ms 256 KB
00-sample-01 AC 1 ms 256 KB
10-small_yes-00 AC 1 ms 256 KB
10-small_yes-01 AC 1 ms 256 KB
10-small_yes-02 AC 1 ms 256 KB
10-small_yes-03 AC 1 ms 256 KB
10-small_yes-04 AC 1 ms 256 KB
10-small_yes-05 AC 1 ms 256 KB
10-small_yes-06 AC 4 ms 640 KB
10-small_yes-07 AC 4 ms 640 KB
10-small_yes-08 AC 4 ms 640 KB
20-small_disturb-00 AC 1 ms 256 KB
20-small_disturb-01 AC 1 ms 256 KB
20-small_disturb-02 AC 1 ms 256 KB
20-small_disturb-03 AC 2 ms 256 KB
20-small_disturb-04 AC 2 ms 256 KB
20-small_disturb-05 AC 2 ms 256 KB
20-small_disturb-06 AC 17 ms 640 KB
20-small_disturb-07 AC 17 ms 640 KB
20-small_disturb-08 AC 15 ms 640 KB
30-large_yes-00 AC 36 ms 3712 KB
30-large_yes-01 AC 36 ms 3584 KB
30-large_yes-02 AC 36 ms 3712 KB
30-large_yes-03 AC 36 ms 3584 KB
30-large_yes-04 AC 36 ms 3712 KB
40-large_disturb-00 AC 300 ms 3712 KB
40-large_disturb-01 AC 333 ms 3712 KB
40-large_disturb-02 AC 307 ms 3712 KB
40-large_disturb-03 AC 317 ms 3712 KB
40-large_disturb-04 AC 343 ms 5632 KB
40-large_disturb-05 AC 299 ms 3712 KB
40-large_disturb-06 AC 331 ms 3712 KB
40-large_disturb-07 AC 321 ms 3712 KB
40-large_disturb-08 AC 325 ms 3712 KB
40-large_disturb-09 AC 345 ms 3712 KB
40-large_disturb-10 AC 304 ms 3712 KB
40-large_disturb-11 AC 309 ms 3712 KB
40-large_disturb-12 AC 312 ms 3712 KB
40-large_disturb-13 AC 343 ms 3712 KB
40-large_disturb-14 AC 336 ms 3712 KB
40-large_disturb-15 AC 305 ms 3712 KB