結果
| 問題 | No.938 賢人を探せ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-30 12:14:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,267 bytes |
| 記録 | |
| コンパイル時間 | 1,752 ms |
| コンパイル使用メモリ | 183,956 KB |
| 実行使用メモリ | 22,472 KB |
| 最終ジャッジ日時 | 2024-06-11 18:59:25 |
| 合計ジャッジ時間 | 8,199 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | TLE * 1 -- * 20 |
ソースコード
#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 = 20005;
vector<vector<int>> graph(2*n,vector<int>());
vector<int> visited(2*n,-1);
void dfs(int i){
if(graph[i].size() == 0) visited[i] = 1;
else{
visited[i] = 0;
for(int p:graph[i]){
if(visited[p] == -1) dfs(p);
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
map<string,int> mp;
int id = 0;
rep(i,n){
string a,b;
cin >> a >> b;
if(mp.find(a) == mp.end()){
mp[a] = id++;
}
if(mp.find(b) == mp.end()){
mp[b] = id++;
}
graph[mp[a]].push_back(mp[b]);
}
rep(i,id){
if(visited[i] != -1) continue;
dfs(i);
}
vector<int> idx;
rep(i,id){
if(visited[i] == 1){
idx.push_back(i);
}
}
vector<string> ans;
for(int i:idx){
for(auto p:mp){
if(i == p.second){
ans.push_back(p.first);
break;
}
}
}
for(string s:ans) cout << s << '\n';
return 0;
}