Submission #75068608


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
    
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
int main() {
    int64_t N;
    cin >> N;
    int64_t M;
    cin >> M;
    int64_t ans = 0;
    Graph G(N);
    for (int64_t i = 0; i < M; i++) {
      int64_t a, b;
      cin >> a >> b;
      G[a-1].push_back(b-1);
    }
     // 頂点 0 をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    dfs(G, 0);
    for (int i = 0; i < N; i++) {
      if (seen.at(i) == true) {
        ans++;
      }
    }
    cout << ans << endl;
    return 0;
  }

Submission Info

Submission Time
Task C - Straw Millionaire
User KOJIKEE
Language C++23 (GCC 15.2.0)
Score 300
Code Size 933 Byte
Status AC
Exec Time 223 ms
Memory 33848 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 22
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 03_killer_00.txt, 03_killer_01.txt, 03_killer_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3564 KiB
00_sample_01.txt AC 1 ms 3428 KiB
00_sample_02.txt AC 1 ms 3564 KiB
01_handmade_00.txt AC 48 ms 5420 KiB
01_handmade_01.txt AC 48 ms 5460 KiB
01_handmade_02.txt AC 48 ms 4984 KiB
01_handmade_03.txt AC 69 ms 6000 KiB
01_handmade_04.txt AC 67 ms 5444 KiB
01_handmade_05.txt AC 222 ms 33800 KiB
01_handmade_06.txt AC 223 ms 33848 KiB
01_handmade_07.txt AC 139 ms 16192 KiB
01_handmade_08.txt AC 140 ms 16076 KiB
01_handmade_09.txt AC 49 ms 9328 KiB
02_random_00.txt AC 147 ms 16580 KiB
02_random_01.txt AC 85 ms 7352 KiB
02_random_02.txt AC 49 ms 5076 KiB
02_random_03.txt AC 100 ms 7620 KiB
02_random_04.txt AC 80 ms 5424 KiB
02_random_05.txt AC 78 ms 5604 KiB
03_killer_00.txt AC 109 ms 16896 KiB
03_killer_01.txt AC 91 ms 16828 KiB
03_killer_02.txt AC 120 ms 27984 KiB