結果
問題 |
No.938 賢人を探せ
|
ユーザー |
|
提出日時 | 2020-03-30 11:34:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,016 bytes |
コンパイル時間 | 1,946 ms |
コンパイル使用メモリ | 190,340 KB |
実行使用メモリ | 814,592 KB |
最終ジャッジ日時 | 2024-06-11 17:17:59 |
合計ジャッジ時間 | 4,445 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 2 MLE * 1 -- * 18 |
ソースコード
#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; }