Submission #64079


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <bits/stdc++.h>
//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) { //多次元初期化
std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) { //最大値更新 返り値はbool
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) { //最小値更新 返り値はbool
if (b < a) {
a = b;
return 1;
}
return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END
Graph graph;
vector<int> min_cost;
void Dijkstra(int s) {
//昇順でfirstを小さい方から取る
min_heap<P> que;
min_cost[s] = 0;
que.emplace(0, s);
while (!que.empty()) {
int now_cost, now_node;
tie(now_cost, now_node) = que.top();
que.pop();
// queの値より新しいcostの方が小さいとき見ない
if (min_cost[now_node] < now_cost) continue;
rep(i, 0, graph[now_node].size()) {
int next_node, next_cost;
tie(next_node, next_cost) = graph[now_node][i];
// 最短経路更新
if (chmin(min_cost[next_node], min_cost[now_node] + next_cost)) {
que.emplace(min_cost[next_node], next_node);
}
}
}
}
signed main(void) {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n, m, c;
cin >> n >> m >> c;
min_cost.resize(n + 1);
graph.resize(n + 1);
rep(i, 0, m) {
int a, b;
cin >> a >> b;
--a, --b;
graph[a].emplace_back(b, 1);
graph[b].emplace_back(a, 1);
}
rep(i, 0, n) {
rep(j, 0, n + 1) min_cost[j] = INF;
Dijkstra(i);
int ans = 0;
rep(j, 0, n) {
if (i != j && min_cost[j] <= c) ++ans;
}
cout << ans << '\n';
}
return 0;
}

ステータス

項目 データ
問題 1406 - 友達の友達は友達?
ユーザー名 r1910
投稿日時 2020-09-16 17:47:06
言語 C++17
状態 Accepted
得点 1
ソースコード長 3187 Byte
最大実行時間 66 ms
最大メモリ使用量 848 KB

セット

セット 得点 Cases
1 ALL 1 / 1 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.text AC 24 ms 604 KB
1
in02.text AC 20 ms 688 KB
1
in03.text AC 19 ms 640 KB
1
in04.text AC 23 ms 468 KB
1
in05.text AC 22 ms 420 KB
1
in06.text AC 22 ms 508 KB
1
in07.text AC 28 ms 576 KB
1
in08.text AC 21 ms 616 KB
1
in09.text AC 18 ms 672 KB
1
in10.text AC 34 ms 700 KB
1
in11.text AC 20 ms 724 KB
1
in12.text AC 26 ms 632 KB
1
in13.text AC 23 ms 660 KB
1
in14.text AC 44 ms 664 KB
1
in15.text AC 66 ms 660 KB
1
in16.text AC 22 ms 652 KB
1
in17.text AC 33 ms 664 KB
1
in18.text AC 27 ms 696 KB
1
in19.text AC 24 ms 768 KB
1
in20.text AC 23 ms 700 KB
1
in21.text AC 55 ms 848 KB
1
in22.text AC 42 ms 712 KB
1
in23.text AC 24 ms 472 KB
1
in24.text AC 26 ms 668 KB
1
in25.text AC 21 ms 704 KB
1
in26.text AC 21 ms 644 KB
1
in27.text AC 25 ms 688 KB
1
in28.text AC 24 ms 728 KB
1
in29.text AC 20 ms 628 KB
1
in30.text AC 29 ms 660 KB
1
samplein01.text AC 20 ms 660 KB
1
samplein02.text AC 25 ms 612 KB
1