Submission #64667


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n"
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }
int main() {
init();
int n, m, c; cin >> n >> m >> c;
vector<VI> g(n);
FOR(i, 0, m) {
int a, b; cin >> a >> b;
--a, --b;
g[a].emplace_back(b);
g[b].emplace_back(a);
}
VI dp;
FOR(i, 0, n) {
int ans = 0;
dp.assign(n, INF);
dp[i] = 0;
queue<int> bfs;
bfs.push(i);
while (!bfs.empty()) {
int cur = bfs.front();
bfs.pop();
for (const int& to : g[cur]) {
if (chmin(dp[to], dp[cur] + 1) && dp[to] <= c) {
++ans;
bfs.push(to);
}
}
}
print(ans);
}
return 0;
}

ステータス

項目 データ
問題 1406 - 友達の友達は友達?
ユーザー名 ir_1st_vil
投稿日時 2020-11-09 21:22:57
言語 C++17
状態 Accepted
得点 1
ソースコード長 3423 Byte
最大実行時間 34 ms
最大メモリ使用量 932 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.text AC 23 ms 604 KB
1
in02.text AC 29 ms 560 KB
1
in03.text AC 21 ms 644 KB
1
in04.text AC 21 ms 600 KB
1
in05.text AC 29 ms 556 KB
1
in06.text AC 19 ms 512 KB
1
in07.text AC 26 ms 580 KB
1
in08.text AC 20 ms 624 KB
1
in09.text AC 22 ms 572 KB
1
in10.text AC 24 ms 636 KB
1
in11.text AC 34 ms 548 KB
1
in12.text AC 24 ms 612 KB
1
in13.text AC 20 ms 780 KB
1
in14.text AC 26 ms 832 KB
1
in15.text AC 29 ms 740 KB
1
in16.text AC 22 ms 756 KB
1
in17.text AC 25 ms 660 KB
1
in18.text AC 21 ms 584 KB
1
in19.text AC 28 ms 664 KB
1
in20.text AC 24 ms 736 KB
1
in21.text AC 29 ms 656 KB
1
in22.text AC 28 ms 812 KB
1
in23.text AC 22 ms 856 KB
1
in24.text AC 23 ms 800 KB
1
in25.text AC 24 ms 720 KB
1
in26.text AC 28 ms 788 KB
1
in27.text AC 24 ms 832 KB
1
in28.text AC 33 ms 896 KB
1
in29.text AC 22 ms 932 KB
1
in30.text AC 31 ms 840 KB
1
samplein01.text AC 17 ms 732 KB
1
samplein02.text AC 24 ms 812 KB
1