链接:http://codeforces.com/gym/101116

学弟写的,以后再补

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
map<string,int>v,ans;
vector<int>que[40020];
string b[40020];
int pre[40020],vis[40020],a[40020],c[40020],d[40020]; void dfs(int x){
if(c[x]==1) ans[b[x]]=1;
vis[x]=1;
for(int i=0;i<que[x].size();i++){
int y=que[x][i];
if(!vis[y]){
dfs(y);
}
}
} int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T,n,m,k,cnt,p;
cin>>T;
string s,s1;
while(T--){
memset(vis,0,sizeof(vis));
memset(c,0,sizeof(c));
cnt=0,p=1;
cin>>n>>m>>k;
for(int i=0;i<n;i++){
cin>>s;
if(!v[s]){
b[p]=s;
v[s]=p++;
}
d[i]=v[s];
}
for(int i=0;i<m;i++){
cin>>s;
if(!v[s]){
b[p]=s;
v[s]=p++;
}
c[v[s]]=1;
}
while(k--){
cin>>s>>s1;
if(!v[s]) {
b[p]=s;
v[s]=p++;
}
if(!v[s1]) {
b[p]=s1;
v[s1]=p++;
}
que[v[s]].push_back(v[s1]);
}
for(int i=0;i<n;i++){
if(!vis[d[i]]){
dfs(d[i]);
}
}
int f=1;
for(auto it : ans){
if(f) f=0,cout<<(it.first);
else cout<<" "<<(it.first);
}
if(!f) cout<<endl;
v.clear(),ans.clear();
for(int i=0;i<40020;i++) que[i].clear();
}
}

  

2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) E的更多相关文章

  1. 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) J

    链接:http://codeforces.com/gym/101116 题意:给出n个点,要求一个矩形框将(n/2)+1个点框住,要面积最小 解法:先根据x轴选出i->j之间的点,中间的点(包括 ...

  2. 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) I

    链接:http://codeforces.com/gym/101116 题意:选六个数,必须出现次数最多,且数字最小,如果出现7优先加入7 解法:排序,出现7优先加入7,最后再将6个数排序 #incl ...

  3. 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) B

    链接:http://codeforces.com/gym/101116 学弟做的,以后再补 #include <iostream> #include <stdio.h> #in ...

  4. 2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6(8/13)

    2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6 比赛连接: http://codeforces.com/gym/101124/ ...

  5. 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7 - HackerEarth Problems Compilation

    B: 思路: 暴力,每两个判断一下; C: 思路: 容斥定理,先枚举脖子下面那个点和那个不可描述的点,算出所有的方案数,这里面有多的腿当成了脖子或者胳膊的,然后就再枚举这种情况把这些减去,又减多了; ...

  6. 2016-2017 CT S03E02: Codeforces Trainings Season 3 Episode 2

    A HHPaint B Square Root C Interesting Places D Road to Home E Ant and apples F Square G Pair H The F ...

  7. 2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6 The Baguette Master

    比赛看不懂 之后不确定题意去瞄了题解,需要分类讨论?囧 之后按照队友已经ac的题意 就是求外面一圈周长,直接可以求得 #include<bits/stdc++.h> using names ...

  8. 2016-2017 CT S03E07: Codeforces Trainings Season 3 Episode 7

    B. Pen Pineapple Apple Pen Solved. 题意:将一个序列合并成一个数. 思路:分类讨论一下, 水. #include<bits/stdc++.h> using ...

  9. 2014-2015 Codeforces Trainings Season 2 Episode 7 G Gophers --线段树

    题意: 有n个地鼠,m个CD碟,每个CD碟有一个影响范围,范围内的地鼠都会被吵到,每次有一个操作就是移动CD碟,然后求每次被影响的地鼠有多少只. 解法: 线段树做.我们只关注地鼠有没有被吵到就可以了, ...

随机推荐

  1. The golden ratio: 1.618

    http://www.chinaz.com/design/2015/1109/467968_2.shtml The golden ratio: 1.618 a/b=b/(a+b) The Fibona ...

  2. java项目中可能会使用到的jar包解释

    一.Struts2 用的版本是struts2.3.1.1 一个简单的Struts项目所需的jar包有如下8个 1. struts2-core-2.3.1.1.jar: Struts2的核心类库. 2. ...

  3. HDU 4832 Chess(DP+组合数学)(2014年百度之星程序设计大赛 - 初赛(第二轮))

    Problem Description 小度和小良最近又迷上了下棋.棋盘一共有N行M列,我们可以把左上角的格子定为(1,1),右下角的格子定为(N,M).在他们的规则中,“王”在棋盘上的走法遵循十字路 ...

  4. paper 6:支持向量机系列三:Kernel —— 介绍核方法,并由此将支持向量机推广到非线性的情况。

    前面我们介绍了线性情况下的支持向量机,它通过寻找一个线性的超平面来达到对数据进行分类的目的.不过,由于是线性方法,所以对非线性的数据就没有办法处理了.例如图中的两类数据,分别分布为两个圆圈的形状,不论 ...

  5. 夺命雷公狗—angularjs—11—service的基本概念

    我们先来研究下service里面的四大服务.. value 变量 constant  常量 factory   工厂模式 service 服务 <!DOCTYPE html> <ht ...

  6. [python] No module named _sysconfigdata_nd

    when setting python environment in Ubuntu13.04, i got this error: ImportError: No module named _sysc ...

  7. Python for z/OS

    Install pythondev Install DB2 or server driver package easy_install ibm_db Get license file from tor ...

  8. ubuntu sublime-text package control

    1.ubuntu 环境下sublime-text的 package control一直配置失败 因为我下的是sublime-text3,而网上一般都是sublime-text2的教程. 2.subli ...

  9. GitHub Desktop for Win 安装不上

    采用了ClickOnce部署方式,网速不给力,安装过程经常断线,要是有离线安装包就好了.

  10. android 学习随笔十九(对话框、样式、主题、国际化 )

    1.对话框 package com.itheima.dialog; import android.os.Bundle; import android.app.Activity; import andr ...