ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205997 | #3699. 车站分级 | hujunyi66 | 100 | 527ms | 9088kb | C++ | 1.8kb | 2024-07-20 18:44:22 | 2024-07-20 20:13:51 |
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int n,m,ans=0,tot=0;
int a[1002],dep[1002],in[1002],is[1002],head[1002],vis[1002][1002];
struct point
{
int to;
int nxt;
}edge[3000010];
inline long long read()
{
long long Sum=0;
int F=1;
char c=getchar();
while(c>'9' || c<'0')
{
if(c=='-')
F=-1;
c=getchar();
}
while(c>='0' && c<='9')
{
Sum=Sum*10+c-'0';
c=getchar();
}
return Sum*F;
}
void add(int u,int v)
{
tot++;
edge[tot].to=v;
edge[tot].nxt=head[u];
head[u]=tot;
}
void Topo_sort()
{
queue<int> q;
for(int i=1;i<=n;i++)
if(in[i]==0)
{
q.push(i);
dep[i]=1;
}
while(!q.empty())
{
int tt=q.front();
q.pop();
for(int i=head[tt];i;i=edge[i].nxt)
{
int v=edge[i].to;
dep[v]=dep[tt]+1;
ans=max(ans,dep[v]);
in[v]--;
if(in[v]==0)
q.push(v);
}
}
}
int main()
{
n=read(),m=read();
for(int i=1;i<=m;i++)
{
memset(a,0,sizeof(a));
memset(is,0,sizeof(is));
int nn;
cin>>nn;
for(int j=1;j<=nn;j++)
{
cin>>a[j];
is[a[j]]=1;
}
for(int j=a[1]+1;j<=a[nn];j++)
if(!is[j])
for(int p=1;p<=nn;p++)
{
if(!vis[j][a[p]])
{
in[a[p]]++;
add(j,a[p]);
vis[j][a[p]]=1;
}
}
}
Topo_sort();
cout<<ans;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1288kb
input:
10 4 4 1 3 5 6 3 3 5 6 3 1 5 9 5 4 5 6 7 9
output:
4
result:
ok single line: '4'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1292kb
input:
10 8 3 1 2 3 3 1 3 5 3 7 8 9 4 1 3 5 6 3 3 5 6 3 1 5 9 5 4 5 6 7 9 3 1 5 10
output:
5
result:
ok single line: '5'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1684kb
input:
100 99 2 1 100 2 2 100 2 3 100 2 4 100 2 5 100 2 6 100 2 7 100 2 8 100 2 9 100 2 10 100 2 11 100 2 1...
output:
94
result:
ok single line: '94'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1652kb
input:
100 99 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33...
output:
53
result:
ok single line: '53'
Test #5:
score: 10
Accepted
time: 1ms
memory: 1488kb
input:
100 100 20 28 39 42 47 48 49 50 54 55 56 57 58 59 61 64 68 69 72 73 75 49 46 47 48 49 50 51 52 53 54...
output:
16
result:
ok single line: '16'
Test #6:
score: 10
Accepted
time: 14ms
memory: 9088kb
input:
1000 999 2 1 1000 2 2 1000 2 3 1000 2 4 1000 2 5 1000 2 6 1000 2 7 1000 2 8 1000 2 9 1000 2 10 1000 ...
output:
994
result:
ok single line: '994'
Test #7:
score: 10
Accepted
time: 255ms
memory: 9052kb
input:
1000 996 1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32...
output:
615
result:
ok single line: '615'
Test #8:
score: 10
Accepted
time: 84ms
memory: 8820kb
input:
1000 1000 26 318 320 321 323 324 327 329 331 333 336 338 340 341 343 344 345 349 350 352 355 356 358...
output:
278
result:
ok single line: '278'
Test #9:
score: 10
Accepted
time: 73ms
memory: 8536kb
input:
1000 1000 134 577 578 579 580 581 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 599 60...
output:
163
result:
ok single line: '163'
Test #10:
score: 10
Accepted
time: 100ms
memory: 1332kb
input:
1000 997 2 16 17 3 16 17 18 4 16 17 18 19 5 16 17 18 19 20 6 16 17 18 19 20 21 7 16 17 18 19 20 21 2...
output:
14
result:
ok single line: '14'