景驰笔试第三题求助

显示超时,一直在60-70%徘徊,求大佬给个思路
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<int>f;
vector<int>zhiling;
vector<int>difang;
map<string, int> chengke;
int times = 0;
char temp_a;
vector<int> v;
vector<int> vv;
int b;
int c;
for (int j = 0; j<m; j++)
{
cin >> temp_a;
if (temp_a == 'T')
{
zhiling.push_back(1);
cin >> b >> c;
v.push_back(b);
vv.push_back(c);
chengke.insert(pair<string, int>(to_string(b), b));
chengke.insert(pair<string, int>(to_string(c), c));
}
else if (temp_a == 'Q')
{
zhiling.push_back(0);
cin >> b;
difang.push_back(b);
chengke.insert(pair<string, int>(to_string(b), b));
}
}
int total = 0;
int p = 0;
while (total<m)
{
if (zhiling[total] == 1)
{
for (std::map<string, int>::iterator it = chengke.begin(); it != chengke.end(); ++it)
{
if (it->second == v[p])
{
chengke[it->first] = vv[p];
}
}
p++;
}
else
{
int uuu = 0;
string poin = to_string(difang[times]);
for (std::map<string, int>::iterator it = chengke.begin(); it != chengke.end(); ++it)
{
if (it->second == chengke[poin])
{
uuu++;
}
}
cout << chengke[poin] << " " << uuu << endl;
times++;
}
total++;
}
}

#景驰科技##笔试题目#
全部评论
用并查集+拆点过了...
点赞 回复
分享
发布于 2018-09-29 23:11
可以试一试用并查集
点赞 回复
分享
发布于 2018-09-29 23:13
滴滴
校招火热招聘中
官网直投
内存超限,第三题只有30,哎
点赞 回复
分享
发布于 2018-09-29 22:44
你做了一道吗
点赞 回复
分享
发布于 2018-09-29 22:54
没理解这题什么意思。
点赞 回复
分享
发布于 2018-09-30 10:39

相关推荐

头像
不愿透露姓名的神秘牛友
04-29 12:10
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务