結果

問題 No.938 賢人を探せ
ユーザー kappybarkappybar
提出日時 2020-03-30 11:34:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,016 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 188,136 KB
実行使用メモリ 814,700 KB
最終ジャッジ日時 2023-09-02 10:36:37
合計ジャッジ時間 5,288 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
11,132 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 40005;
vector<vector<int>> graph(n,vector<int>());
vector<int> visited(n,-1);

void dfs(int i){
    if(graph[i].size() == 0) visited[i] = 1;
    else{
        visited[i] = 0;
        for(int p:graph[i]){
            dfs(p);
        }
    }
}

int main(){
    int n;
    cin >> n;
    map<int ,string> mp1;
    map<string,int> mp2;
    int id = 0;
    rep(i,n){
        string a,b;
        cin >> a >> b;
        if(mp2.count(a) == 0){
            mp2[a] = id;
            mp1[id++] = a;
        }
        if(mp2.count(b) ==0){
            mp2[b] = id;
            mp1[id++] = b;
        }
        graph[mp2[a]].push_back(mp2[b]);
    }

    rep(i,id){
        if(visited[i] != -1) continue;
        dfs(i);
    }

    rep(i,id){
        if(visited[i] == 1){
            cout << mp1[i] << endl;
        }
    }

    return 0;
}
0