QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#392193#8031. GitignoreSocialPandaTL 1ms3844kbC++141.4kb2024-04-17 11:07:322024-04-17 11:07:33

Judging History

你现在查看的是最新测评结果

  • [2024-04-17 11:07:33]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3844kb
  • [2024-04-17 11:07:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define PII pair<int,int>
#define pb push_back
#define fi first
#define se second

void solve()
{
	vector<vector<int>> v(10000);
	map<string,int> rt;
	map<string,int> mp;
	map<int,int> sn;
	int idx=1;
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		string tmp,word;
		string father;
		cin>>tmp;tmp+='/';
		for(auto z:tmp)
		{
			if(z=='/')
			{
				if(mp[word]==0) mp[word]=idx++;
				sn[mp[word]]=0;
				if(father.empty())
				{
					rt[word]=1;
				}
				else
				{
					v[mp[father]].pb(mp[word]);
				}
				father=word;
				word.clear();
			}
			else word+=z;
		}
	}
	for(int i=1;i<=m;i++)
	{
		string tmp,word;
		cin>>tmp;tmp+='/';
		string father;
		for(auto z:tmp)
		{
			if(z=='/')
			{
				if(mp[word]==0) mp[word]=idx++;
				sn[mp[word]]=1;
				if(father.empty())
				{
					rt[word]=1;
				}
				else
				{
					v[mp[father]].pb(mp[word]);
				}
				father=word;
				word.clear();
			}
			else word+=z;
		}
	}
	int ans=0;
	for(auto z:rt)
	{
		//cout<<bfs(mp[z.fi])<<' ';
		queue<int> q;
		q.push(mp[z.fi]);
		while(q.size())
		{
			int cur=q.front();
			q.pop();
			if(sn[cur]==0) ans++;
			else
			{
				for(auto z:v[cur])
				{
					q.push(z);
				}
			}
		}
	}
	cout<<ans<<endl;
}

int main()
{
	int T=1;
	cin>>T;
	while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3844kb

input:

2
3 0
data/train
data/test
model
3 1
data/train
data/test
model
data/sample

output:

2
3

result:

ok 2 number(s): "2 3"

Test #2:

score: -100
Time Limit Exceeded

input:

5
0 10
szhps/mb/yz
szhps/mb/fb/rf/auw
szhps/or/ui
hy/xkd/k
szhps/mb/fb/rf/mu
cf/rnd/wjv/xdda
szhps/izh
gi
szhps/mb/fb/xwe
hy/xkd/jbq
0 20
gjy/imp/mxuvi/z/ao
gjy/s/zft/jxzm
gjy/ob/mwvf/la
gjy/imp/supe/oxne/p
gjy/ob/mwvf/eums/agfb
gjy/imp/mxuvi/z/anaj
gjy/ob/mwvf/eums/tv
gjy/ob/mwvf/eums/x/gg
gjy/s/ak...

output:

0
0
0
0

result: