QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#706427 | #8070. A Complex Problem | kkkaaa | RE | 1ms | 6160kb | C++14 | 2.1kb | 2024-11-03 11:16:08 | 2024-11-03 11:16:10 |
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5496kb
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: 5428kb
input:
1 0 P NP
output:
1 2
result:
ok single line: '1 2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5484kb
input:
0 1 R ALL
output:
2 2
result:
ok single line: '2 2'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6160kb
input:
3 0 QMIP MIPstar MIPstar RE RE QMIP
output:
1 1
result:
ok single line: '1 1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
11 8 NC P P BPP P coNP P NP BPP BQP coNP PSPACE BQP PSPACE NP PSPACE PSPACE EXPTIME EXPTIME NEXPTIME NEXPTIME EXPSPACE REG CFL CFL NC CFL CSL NC PSPACE CSL PSPACE EXPSPACE R R RE RE ALL
output:
7 16
result:
ok single line: '7 16'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5504kb
input:
5 4 A B E B B G H C E G A D D E G H B C
output:
4 7
result:
ok single line: '4 7'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5984kb
input:
6 3 B G H C E B B C A D A B D E G H E G
output:
4 7
result:
ok single line: '4 7'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5592kb
input:
5 4 B C A B A D E G H C B G D E G H E B
output:
5 7
result:
ok single line: '5 7'
Test #9:
score: 0
Accepted
time: 1ms
memory: 5508kb
input:
23 6 AA AB AB AC AC AD AC AM AD ADB ADB ADC ADC ADD ADC AE ADD AD AN ADD ADD AE AE AH AE AF AF AG AG AH AH AI AI ADC AI AJ AJ ADB AJ AC AJ AK AK AL AK AA AG BF AH BE AI BD AJ BC AK BB AA BA
output:
2 10
result:
ok single line: '2 10'
Test #10:
score: 0
Accepted
time: 1ms
memory: 5528kb
input:
6 3 B G H C E B B C A D A B D E G H E H
output:
3 7
result:
ok single line: '3 7'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5792kb
input:
50 2 AA AB AB AC AC AD AC AM AD ADB ADB ADC ADC ADD ADC AE ADD AD AN ADD ADD AE AE AH AE AF AF AG AG AH AH AI AI ADC AI AJ AJ ADB AJ AC AJ AK AK AL AK AA AG BF AH BE AI BD AJ BC AK BB BA BB BB BC BC BD BD BE BE BF BA CA BB CB BC CC BD CD BE CE CA CZA CZA CB CB CZB CZB CC CC CZC CZC CD CD CZD CZD CE ...
output:
3 11
result:
ok single line: '3 11'
Test #12:
score: 0
Accepted
time: 0ms
memory: 5500kb
input:
23 12 AA AB AB AC AC AD AC AM AD ADB ADB ADC ADC ADD ADC AE ADD AD AN ADD ADD AE AE AH AE AF AF AG AG AH AH AI AI ADC AI AJ AJ ADB AJ AC AJ AK AK AL AK AA AG BF AH BE AI BD AJ BC AK BB AA BA BA CA BB CB BC CC BD CD BE CE BF CF
output:
3 16
result:
ok single line: '3 16'
Test #13:
score: 0
Accepted
time: 1ms
memory: 5500kb
input:
33 12 AA AB AB AC AC AD AC AM AD ADB ADB ADC ADC ADD ADC AE ADD AD AN ADD ADD AE AE AH AE AF AF AG AG AH AH AI AI ADC AI AJ AJ ADB AJ AC AJ AK AK AL AK AA CF CE CE CD CD CC CC CB CB CA CA CF CA CXA CB CXB CC CXC CD CXD AG BF AH BE AI BD AJ BC AK BB AA BA BA CA BB CB BC CC BD CD BE CE BF CF
output:
3 15
result:
ok single line: '3 15'
Test #14:
score: 0
Accepted
time: 0ms
memory: 5564kb
input:
51 2 BF BA AA AB AB AC AC AD AC AM AD ADB ADB ADC ADC ADD ADC AE ADD AD AN ADD ADD AE AE AH AE AF AF AG AG AH AH AI AI ADC AI AJ AJ ADB AJ AC AJ AK AK AL AK AA AG BF AH BE AI BD AJ BC AK BB BA BB BB BC BC BD BD BE BE BF BA CA BB CB BC CC BD CD BE CE CA CZA CZA CB CB CZB CZB CC CC CZC CZC CD CD CZD C...
output:
3 6
result:
ok single line: '3 6'
Test #15:
score: -100
Runtime Error
input:
0 47356 fpo axqt yhk axqy bbq aliw arbj sol abau addo ufv bbqr bakb acn ofb ods bdge bebp vhp afqc ysv zyp adfw asfm fcz aygg bdkx msx ajwv avsz agdd bnwv niq muj agrl bhrp aggr aces oot bmum acmy anjr apq hyi bduj pxy bmzk smz bnxq aqzj aycy pzf akzu mbx fly aegu asff avrf aeup aufq bpdp wbj alnr b...