結果
| 問題 | 
                            No.938 賢人を探せ
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-12-01 06:54:42 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 77 ms / 2,000 ms | 
| コード長 | 1,010 bytes | 
| コンパイル時間 | 1,132 ms | 
| コンパイル使用メモリ | 98,884 KB | 
| 最終ジャッジ日時 | 2025-01-08 06:33:11 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 21 | 
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <queue>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
const ll mod = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  set<string> cheater, clean;
  for (int i = 0; i < n; i++) {
    cheater.insert(a[i]);
    auto it1 = clean.find(a[i]);
    if (it1 != clean.end()) clean.erase(it1);
    auto it2 = cheater.find(b[i]);
    if (it2 == cheater.end()) clean.insert(b[i]);
  }
  vector<string> ans;
  set<string> checked;
  for (int i = 0; i < n; i++) {
    auto it1 = clean.find(b[i]);
    auto it2 = checked.find(b[i]);
    if (it1 != clean.end() && it2 == checked.end()) {
      ans.push_back(b[i]);
      checked.insert(b[i]);
    }
  }
  for (auto &x: ans) cout << x << endl;
  return 0;
}