QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706207#8070. A Complex ProblemkkkaaaCompile Error//C++171.8kb2024-11-03 09:20:002024-11-03 09:20:00

Judging History

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

  • [2024-11-03 09:20:00]
  • 评测
  • [2024-11-03 09:20:00]
  • 提交

answer

#include<bits/stdc++.h>
#define PB push_back
using namespace std;
const int N(10005);
int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N];
int tot, partnum;
vector<int> eg[N], EG[N];
stack<int> q;
void tarjan(int x)
{
	dfn[x] = low[x] = ++tot;
	q.push(x), visit[x] = 1;
	for(int i = 0; i < eg[x].size(); ++i)
	{
		if(!dfn[eg[x][i]])
		{
			tarjan(eg[x][i]);
			low[x] = min(low[x], low[eg[x][i]]);
		}
		else if(visit[eg[x][i]]) low[x] = min(low[x], dfn[eg[x][i]]);
		//注意一下low = min(low[x], low[eg[x][i]]); 有待思考
	}
	if(dfn[x] == low[x])
	{
		++partnum;
		int y;
		do
		{
			y = q.top(); q.pop();
			visit[y] = 0;
			part[y] = partnum;
			WLTH[partnum] += wlth[y];
		}while(y != x);
	}
}
int dis[N];
void topo()
{
	queue<int> q;
	for(int i = 1; i <= partnum; ++i) if(!du[i]) q.push(i), dis[i] = WLTH[i];
	while(!q.empty())
	{
		int x = q.front(); q.pop();
		for(int i = 0; i < EG[x].size(); ++i)
		{
			dis[EG[x][i]] = max(dis[EG[x][i]], dis[x]+WLTH[EG[x][i]]);
			--du[EG[x][i]];
			if(!du[EG[x][i]]) q.push(EG[x][i]);
		}
	}
	int ans = 0;
	for(int i = 1; i <= partnum; ++i) ans = max(ans, dis[i]);
	cout<<ans<<endl;
}
map<string, int> mp;
int tt;
int main()
{
	//freopen("1.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m; cin>>n>>m;
	for(int i = 1; i <= n; ++i) {
		string x, y; cin>>x>>y;
		if(!mp.count(x)) mp[x] = ++tt;
		if(!mp.count(y)) mp[y] = ++tt;
		eg[mp[x]].PB(mp[y]);
	}
	int tot = mp.size();
	int KK = 0;
	for(int i = 1; i <= tt; ++i) if(!dfn[i]) tarjan(i), KK++;
	int add = 0;
	for(int i = 1; i <= m; ++i)
	{
		string x, y; cin >> x >> y;
		if(!mp.count(x)) mp[x] = ++tt, add++;
		if(!mp.count(y)) mp[y] = ++tt, add++;
	}
	cout<<KK+add<<" "<<add+partnum<<endl;
	return 0;
}

详细

answer.code: In function ‘void tarjan(int)’:
answer.code:12:20: error: reference to ‘visit’ is ambiguous
   12 |         q.push(x), visit[x] = 1;
      |                    ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:80,
                 from answer.code:1:
/usr/include/c++/13/variant:1827:5: note: candidates are: ‘template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)’
 1827 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
answer.code:5:39: note:                 ‘int visit [10005]’
    5 | int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N];
      |                                       ^~~~~
answer.code:20:25: error: reference to ‘visit’ is ambiguous
   20 |                 else if(visit[eg[x][i]]) low[x] = min(low[x], dfn[eg[x][i]]);
      |                         ^~~~~
/usr/include/c++/13/variant:1827:5: note: candidates are: ‘template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)’
 1827 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
answer.code:5:39: note:                 ‘int visit [10005]’
    5 | int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N];
      |                                       ^~~~~
answer.code:30:25: error: reference to ‘visit’ is ambiguous
   30 |                         visit[y] = 0;
      |                         ^~~~~
/usr/include/c++/13/variant:1827:5: note: candidates are: ‘template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)’
 1827 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
answer.code:5:39: note:                 ‘int visit [10005]’
    5 | int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N];
      |                                       ^~~~~