提交记录 9833


用户 题目 状态 得分 用时 内存 语言 代码长度
memset0 noi19a. 【NOI2019】回家路线 Accepted 100 280.148 ms 101580 KB C++11 3.65 KB
提交时间 评测时间
2019-07-16 17:35:31 2020-08-01 01:55:35
// =================================
//   author: memset0
//   date: 2019.07.16 08:30:00
//   website: https://memset0.cn/
// =================================
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define rep(i, l, r) for (int i = (l), i##ed = (r); i <= i##ed; ++i)
#define for_each(i, a) for (size_t i = 0, i##ed = a.size(); i < i##ed; ++i)
namespace ringo {

template <class T> inline void read(T &x) {
  x = 0; char c = getchar(); bool f = 0;
  while (!isdigit(c)) f ^= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  if (f) x = -x;
}
template <class T> inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar('0' + x % 10);
}
template <class T> inline void print(T x, char c) { print(x), putchar(c); }
template <class T> inline void print(T a, int l, int r, std::string s = "") {
  if (s != "") std::cout << s << ": ";
  for (int i = l; i <= r; i++) print(a[i], " \n"[i == r]);
}

const int N = 4e5 + 10;
ll ans, dis[N];
std::vector<int> G[N];
int n, m, cnt, A, B, C;
std::map<int, int> map[N];
int ind[N], rnk[N], tag[N];
std::vector<std::pair<int, int> > v_map[N];

struct info_s {
  int u, x, id;
  inline bool operator<(const info_s &other) const {
    return x > other.x;
  }
} info[N];
std::priority_queue<info_s> q;

struct edge_s {
  int u, v, x, y;
} edge[N];

inline ll super_min(ll x, ll y) {
  if (x == -1) return y;
  if (y == -1) return x;
  if (x < y) return x;
  return y;
}

inline int calc(int x) {
  return A * x * x + B * x + C;
}

inline int get_id(int u, int x) {
  std::map<int, int>::iterator it = map[u].find(x);
  if (it != map[u].end()) return it->second;
  map[u][x] = ++cnt;
  info[cnt] = (info_s){u, x, cnt};
  return cnt;
}

inline int get_dis(const info_s &node) {
  int res = -1;
  for (int i = 0; i <= rnk[node.id]; i++) {
    std::pair<int, int> it = v_map[node.u][i];
    if (~dis[it.second])
      res = super_min(res, dis[it.second] + calc(node.x - it.first));
  }
  return res;
}

void main() {
  memset(dis, -1, sizeof(dis));
  read(n), read(m), read(A), read(B), read(C);
  map[1][0] = cnt = 1, info[1] = (info_s){1, 0, 1};
  for (int i = 1, u, v, x, y; i <= m; i++) {
    read(u), read(v), read(x), read(y);
    edge[i] = (edge_s){u, v, x, y};
    int U = get_id(u, x), V = get_id(v, y);
    G[U].push_back(V), ++ind[V];
    // printf("edge: %d %d %d %d [%d %d]\n", u, v, x, y, U, V);
  }
  for (int i = 1; i <= n; i++) {
    for (std::map<int, int>::iterator it = map[i].begin(); it != map[i].end(); it++) {
      rnk[it->second] = v_map[i].size();
      v_map[i].push_back(std::make_pair(it->first, it->second));
    }
  }
  for (int i = 1; i <= cnt; i++)
    if (!ind[i]) q.push(info[i]);
  dis[1] = 0;
  while (q.size()) {
    info_s it = q.top(); q.pop();
    // printf("> %d %d %d\n", it.u, it.x, it.id);
    int u = it.id, base = get_dis(it);
    tag[u] = 1;
    for (std::vector<int>::iterator it = G[u].begin(); it != G[u].end(); it++) {
      int v = *it;
      if (~base);
        dis[v] = super_min(base, dis[v]);
      if (!--ind[v])
        q.push(info[v]);
    }
  }
  ans = -1;
  for (std::map<int, int>::iterator it = map[n].begin(); it != map[n].end(); it++)
    if (~dis[it->second])
      ans = super_min(ans, dis[it->second] + it->first);
  print(ans, '\n');
  // print(dis, 1, cnt);
  // for (int i = 1; i <= cnt; i++)
  //   printf("info[%d] => {%d, %d} => %d\n", i, info[i].u, info[i].x, ind[i]);
}

} signed main() {
#ifdef memset0
  freopen("1.in", "r", stdin);
#else
  freopen("route.in", "r", stdin);
  freopen("route.out", "w", stdout);
#endif
  ringo::main();
  // std::cerr << "clock: " << clock() / (double)CLOCKS_PER_SEC << std::endl;
  return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #16.942 ms39 MB + 784 KBAcceptedScore: 5

Testcase #26.872 ms39 MB + 784 KBAcceptedScore: 5

Testcase #36.87 ms39 MB + 784 KBAcceptedScore: 5

Testcase #47.045 ms39 MB + 780 KBAcceptedScore: 5

Testcase #59.049 ms40 MB + 988 KBAcceptedScore: 5

Testcase #69.011 ms40 MB + 952 KBAcceptedScore: 5

Testcase #78.842 ms40 MB + 884 KBAcceptedScore: 5

Testcase #88.81 ms40 MB + 896 KBAcceptedScore: 5

Testcase #98.925 ms40 MB + 852 KBAcceptedScore: 5

Testcase #108.887 ms40 MB + 888 KBAcceptedScore: 5

Testcase #118.99 ms40 MB + 864 KBAcceptedScore: 5

Testcase #129.009 ms40 MB + 992 KBAcceptedScore: 5

Testcase #138.878 ms40 MB + 960 KBAcceptedScore: 5

Testcase #148.884 ms40 MB + 908 KBAcceptedScore: 5

Testcase #15246.637 ms90 MB + 900 KBAcceptedScore: 5

Testcase #16278.07 ms98 MB + 800 KBAcceptedScore: 5

Testcase #17247.435 ms94 MB + 16 KBAcceptedScore: 5

Testcase #18280.148 ms99 MB + 204 KBAcceptedScore: 5

Testcase #19252.852 ms94 MB + 716 KBAcceptedScore: 5

Testcase #20279.987 ms99 MB + 188 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-30 15:26:41 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠