QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708768 | #8070. A Complex Problem | jerry2423 | Compile Error | / | / | C++17 | 2.0kb | 2024-11-04 06:08:16 | 2024-11-04 06:08:17 |
Judging History
answer
#include<bits/stdc++.h>
#define PB push_back
using namespace std;
const int N(20005);
int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N];
int tot, partnum;
vector<int> eg[N], EG[N], egn[N], EGN[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] = 1;
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]+EGN[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;
}
map<string, int> mp;
int viss[N];
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]);
egn[mp[x]].PB(0);
}
int tot = mp.size();
for(int i = 1; i <= tt; ++i) if(!dfn[i]) tarjan(i);
for(int i = 1; i <= m; ++i)
{
string x, y; cin >> x >> y;
if(!mp.count(x)) mp[x] = ++tt;
if(!mp.count(y)) mp[y] = ++tt;
if(!part[mp[x]]) part[mp[x]] = ++partnum;
if(!part[mp[y]]) part[mp[y]] = ++partnum;
eg[mp[x]].PB(mp[y]);
egn[mp[x]].PB(1);
}
for(int i = 1; i <= tt; ++i)
for(int j = 0; j < eg[i].size(); ++j)
if(part[i] != part[eg[i][j]])
EG[part[i]].PB(part[eg[i][j]]), du[part[eg[i][j]]]++,
EGN[part[i]].PB(egn[i][j]);
topo();
cout<<" "<<partnum<<endl;
return 0;
}
详细
answer.code: In function ‘void tarjan(int)’: answer.code:12:12: 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 [20005]’ 5 | int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N]; | ^~~~~ answer.code:20:9: 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 [20005]’ 5 | int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N]; | ^~~~~ answer.code:30:1: 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 [20005]’ 5 | int wlth[N], WLTH[N], dfn[N], low[N], visit[N], part[N], du[N]; | ^~~~~ answer.code: In function ‘int main()’: answer.code:60:8: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 60 | freopen("1.in","r",stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~