QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#706232 | #8070. A Complex Problem | kkkaaa | WA | 1ms | 4296kb | C++14 | 1.8kb | 2024-11-03 09:33:36 | 2024-11-03 09:33:36 |
Judging History
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<<add+1<<" "<<add+partnum<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4032kb
input:
6 2 A B B C C A A D D E E A F B E G
output:
3 3
result:
ok single line: '3 3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4260kb
input:
1 0 P NP
output:
1 2
result:
ok single line: '1 2'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 4296kb
input:
0 1 R ALL
output:
3 2
result:
wrong answer 1st lines differ - expected: '2 2', found: '3 2'