답안 #280294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
280294 2020-08-22T15:37:13 Z Haunted_Cpp Hotspot (NOI17_hotspot) C++17
64 / 100
2500 ms 1812 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 5000 + 5;
const int MAX_K = 2000 + 5;

vector<vector<int>> g(MAX_N);
vector<long double> ans(MAX_N);

int solve(int node, int target, const vector<vector<int>> &dag, vector<int> &dp) {
  if (node == target) return 1;
  int &res = dp[node];
  if (~res) return res;
  res = 0;
  for (auto to : dag[node]) {
    res += solve(to, target, dag, dp);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int st, et;
    cin >> st >> et;
    g[st].emplace_back(et);
    g[et].emplace_back(st);
  }
  auto bfs = [&](int source, int sink) {
    queue<int> q;
    vector<int> dist(n, 1e9);
    dist[sink] = 0;
    q.push(sink);
    while(!q.empty()) {
      int node = q.front();
      q.pop();
      for (auto to : g[node]) {
        if (dist[to] > dist[node] + 1) {
          dist[to] = dist[node] + 1;
          q.push(to);
        }
      }
    }
    vector<vector<int>> dag(MAX_N);
    set<pair<int, int>> add;
    function<void(int)> build_dag = [&](int node) {
      const int cur = dist[node];
      for (auto to : g[node]) {
        if (dist[to] == cur - 1) {
          add.insert({node, to});
          build_dag(to);
        }
      }
    };
    build_dag(source);
    for (auto to : add) {
      dag[to.first].emplace_back(to.second);
    }
    return dag;
  };
  int k;
  cin >> k;
  while(k--) {
    int source, sink;
    cin >> source >> sink;
    vector<vector<int>> a = bfs(source, sink);
    vector<int> dp_a(MAX_N, -1);
    vector<vector<int>> b = bfs(sink, source);
    vector<int> dp_b(MAX_N, -1);
    const int cnt_shortest = solve(source, sink, a, dp_a);
    if (cnt_shortest == 0) continue;
    for (int i = 0; i < n; i++) {
      int L = solve(i, sink, a, dp_a);
      int R = solve(i, source, b, dp_b);
      ans[i] += (long double)L / (long double)cnt_shortest * (long double)R;
    }
  }
  cout << (max_element(ans.begin(), ans.end()) - ans.begin()) << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 896 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 896 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 896 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 9 ms 912 KB Output is correct
9 Correct 14 ms 964 KB Output is correct
10 Correct 19 ms 964 KB Output is correct
11 Correct 26 ms 1040 KB Output is correct
12 Correct 11 ms 872 KB Output is correct
13 Correct 15 ms 860 KB Output is correct
14 Correct 31 ms 1540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 896 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 9 ms 912 KB Output is correct
16 Correct 14 ms 964 KB Output is correct
17 Correct 19 ms 964 KB Output is correct
18 Correct 26 ms 1040 KB Output is correct
19 Correct 11 ms 872 KB Output is correct
20 Correct 15 ms 860 KB Output is correct
21 Correct 31 ms 1540 KB Output is correct
22 Correct 7 ms 872 KB Output is correct
23 Correct 10 ms 872 KB Output is correct
24 Correct 17 ms 884 KB Output is correct
25 Correct 18 ms 896 KB Output is correct
26 Correct 17 ms 888 KB Output is correct
27 Correct 16 ms 868 KB Output is correct
28 Correct 23 ms 872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 896 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 3 ms 896 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 12 ms 960 KB Output is correct
18 Correct 7 ms 960 KB Output is correct
19 Correct 9 ms 1000 KB Output is correct
20 Correct 5 ms 896 KB Output is correct
21 Correct 3 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 896 KB Output is correct
3 Correct 2 ms 896 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 9 ms 912 KB Output is correct
16 Correct 14 ms 964 KB Output is correct
17 Correct 19 ms 964 KB Output is correct
18 Correct 26 ms 1040 KB Output is correct
19 Correct 11 ms 872 KB Output is correct
20 Correct 15 ms 860 KB Output is correct
21 Correct 31 ms 1540 KB Output is correct
22 Correct 7 ms 872 KB Output is correct
23 Correct 10 ms 872 KB Output is correct
24 Correct 17 ms 884 KB Output is correct
25 Correct 18 ms 896 KB Output is correct
26 Correct 17 ms 888 KB Output is correct
27 Correct 16 ms 868 KB Output is correct
28 Correct 23 ms 872 KB Output is correct
29 Correct 3 ms 896 KB Output is correct
30 Correct 2 ms 896 KB Output is correct
31 Correct 12 ms 960 KB Output is correct
32 Correct 7 ms 960 KB Output is correct
33 Correct 9 ms 1000 KB Output is correct
34 Correct 5 ms 896 KB Output is correct
35 Correct 3 ms 924 KB Output is correct
36 Correct 218 ms 1076 KB Output is correct
37 Correct 470 ms 1256 KB Output is correct
38 Correct 1632 ms 1776 KB Output is correct
39 Execution timed out 2535 ms 1812 KB Time limit exceeded
40 Halted 0 ms 0 KB -