Submission #70469789
Source Code Expand
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <numeric>
#include <stack>
#include <cassert>
#include <cstring>
#include <cmath>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <chrono>
#include <sstream>
#include <limits>
#include <functional>
using namespace std;
#define endl '\n'
// #define LOCAL
using int64 = int64_t;
using uint64 = unsigned long long;
using int128 = __int128_t;
#ifdef LOCAL
#include "src/debug.h"
#else
#define debug(...) 42
#endif
int N, M;
vector<vector<int>> adj;
string S;
vector<int64> bfs(int src) {
vector<int64> ans(N, 0);
vector<vector<int>> vis(N, vector<int>(2, -1));
queue<pair<int, int>> q;
for (int i = 0; i < N; ++i) {
if (S[i] == 'S') {
q.emplace(i, i);
}
}
int steps = 0;
while (!q.empty()) {
int sz = q.size();
for (int i = 0; i < sz; ++i) {
auto [u, src] = q.front();
if (S[u] == 'D') ans[u] += steps;
// cout << "At node " << u << " from source " << src << " at step " << steps << endl;
q.pop();
for (int v : adj[u]) {
if (vis[v][0] == src || vis[v][1] == src) continue;
if (vis[v][0] == -1) {
vis[v][0] = src;
q.emplace(v, src);
} else if (vis[v][1] == -1) {
vis[v][1] = src;
q.emplace(v, src);
}
}
}
steps++;
}
return ans;
}
void solve() {
cin >> N >> M;
adj.assign(N, vector<int>());
for (int i = 0; i < M; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
cin >> S;
vector<int64> ans = bfs(0);
for (int64 x : ans) {
if (!x) continue;
cout << x << endl;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Hit and Away |
| User | therealchainman |
| Language | C++ 20 (gcc 12.2) |
| Score | 450 |
| Code Size | 2190 Byte |
| Status | AC |
| Exec Time | 121 ms |
| Memory | 30720 KiB |
Compile Error
Main.cpp: In function ‘std::vector<long int> bfs(int)’:
Main.cpp:39:23: warning: unused parameter ‘src’ [-Wunused-parameter]
39 | vector<int64> bfs(int src) {
| ~~~~^~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 450 / 450 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example_00.txt | AC | 1 ms | 3360 KiB |
| example_01.txt | AC | 1 ms | 3400 KiB |
| hand_00.txt | AC | 117 ms | 26608 KiB |
| hand_01.txt | AC | 105 ms | 28376 KiB |
| hand_02.txt | AC | 83 ms | 30100 KiB |
| hand_03.txt | AC | 66 ms | 30704 KiB |
| hand_04.txt | AC | 71 ms | 29104 KiB |
| hand_05.txt | AC | 17 ms | 6136 KiB |
| hand_06.txt | AC | 18 ms | 6060 KiB |
| hand_07.txt | AC | 106 ms | 26580 KiB |
| hand_08.txt | AC | 49 ms | 17188 KiB |
| hand_09.txt | AC | 17 ms | 5152 KiB |
| hand_10.txt | AC | 79 ms | 26568 KiB |
| hand_11.txt | AC | 67 ms | 28516 KiB |
| hand_12.txt | AC | 67 ms | 28372 KiB |
| hand_13.txt | AC | 66 ms | 30096 KiB |
| hand_14.txt | AC | 66 ms | 30720 KiB |
| hand_15.txt | AC | 68 ms | 30680 KiB |
| random_00.txt | AC | 88 ms | 27256 KiB |
| random_01.txt | AC | 89 ms | 27292 KiB |
| random_02.txt | AC | 88 ms | 27256 KiB |
| random_03.txt | AC | 89 ms | 27092 KiB |
| random_04.txt | AC | 91 ms | 27336 KiB |
| random_05.txt | AC | 89 ms | 27360 KiB |
| random_06.txt | AC | 93 ms | 26508 KiB |
| random_07.txt | AC | 108 ms | 26748 KiB |
| random_08.txt | AC | 100 ms | 27260 KiB |
| random_09.txt | AC | 109 ms | 26656 KiB |
| random_10.txt | AC | 106 ms | 26736 KiB |
| random_11.txt | AC | 95 ms | 27292 KiB |
| random_12.txt | AC | 98 ms | 26696 KiB |
| random_13.txt | AC | 97 ms | 26816 KiB |
| random_14.txt | AC | 107 ms | 27152 KiB |
| random_15.txt | AC | 113 ms | 26788 KiB |
| random_16.txt | AC | 121 ms | 26736 KiB |
| random_17.txt | AC | 104 ms | 26928 KiB |
| random_18.txt | AC | 12 ms | 4476 KiB |
| random_19.txt | AC | 15 ms | 4796 KiB |
| random_20.txt | AC | 16 ms | 5616 KiB |
| random_21.txt | AC | 17 ms | 5376 KiB |
| random_22.txt | AC | 16 ms | 5068 KiB |
| random_23.txt | AC | 13 ms | 4548 KiB |
| random_24.txt | AC | 38 ms | 7188 KiB |
| random_25.txt | AC | 33 ms | 7180 KiB |
| random_26.txt | AC | 32 ms | 7004 KiB |
| random_27.txt | AC | 30 ms | 6964 KiB |
| random_28.txt | AC | 38 ms | 7812 KiB |
| random_29.txt | AC | 33 ms | 7016 KiB |
| random_30.txt | AC | 88 ms | 25844 KiB |
| random_31.txt | AC | 64 ms | 18708 KiB |
| random_32.txt | AC | 73 ms | 19156 KiB |
| random_33.txt | AC | 86 ms | 28068 KiB |
| random_34.txt | AC | 68 ms | 17368 KiB |
| random_35.txt | AC | 73 ms | 18860 KiB |