結果

問題 No.812 Change of Class
ユーザー hide1214hide1214
提出日時 2019-04-12 22:18:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,356 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 115,196 KB
実行使用メモリ 13,720 KB
最終ジャッジ日時 2023-09-03 13:09:12
合計ジャッジ時間 12,970 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
4,604 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 14 ms
6,952 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 6 ms
4,740 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 6 ms
4,568 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 270 ms
10,212 KB
testcase_56 AC 333 ms
12,188 KB
testcase_57 AC 354 ms
12,812 KB
testcase_58 AC 179 ms
7,932 KB
testcase_59 AC 398 ms
13,720 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222



struct Weighted_Graph {
  struct edge { ll node, cost; };
  vector<vector<edge>> e;

  Weighted_Graph(ll x = MAX) { e.resize(x + 1); }

  void add_edge(ll a, ll b, ll c) { e[a].pb(edge{ b,c }); }

  vll dijkstra(ll start) {
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    ll u;
    pll p;
    vll dist(e.size(), inf);
    dist[start] = 0;
    pq.push(pll(0, start));

    while (!pq.empty()) {
      p = pq.top(); pq.pop();
      u = p.second;
      if (dist[u] < p.first) continue;
      for (edge e1 : e[u]) {
        if (dist[e1.node] > dist[u] + e1.cost) {
          dist[e1.node] = dist[u] + e1.cost;
          pq.push(pll(dist[e1.node], e1.node));
        }
      }
    }
    return dist;
  }

};



int main(void) {
  ios::sync_with_stdio(false); cin.tie(0);


  cin >> n >> m;
  Weighted_Graph wg(n);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    wg.add_edge(a, b, 1);
    wg.add_edge(b, a, 1);
  }
  cin >> m;
  rep(i, m) {
    ll a;
    cin >> a;
    vll v = wg.dijkstra(a);
    ans = 0;
    ma = 0;
    FOR(i, 1, n + 1) {
      if (v[i] > inf / 2) continue;
      ma = max(ma, v[i]);
      ans++;
    }
    if (ma == 1) ma = 0;
    cout << ans - 1 << " " << (ma + 1) / 2 << endl;
  }


  

  return 0;
}
0