QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#589963 | #8943. Challenge Matrix Multiplication | yhddd | WA | 1ms | 6096kb | C++20 | 1.6kb | 2024-09-25 20:50:48 | 2024-09-25 20:50:50 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,m;
vector<int> e[maxn],g[maxn];
int d[maxn];
int st[maxn],tp;
int ans[maxn];
bool vis[maxn];
queue<int> q;
void work(){
n=read();m=read();
for(int i=1;i<=m;i++){
int u=read(),v=read();
e[u].pb(v),g[u].pb(v);
d[u]++,d[v]--;
}
for(int t=1;t<=60;t++){
int p=0;for(int i=1;i<=n;i++)if(d[i]>0){p=i;break;}
if(!p)break;
tp=0;d[p]--;
while(d[p]>=0){
st[++tp]=p;
int v=e[p].back();e[p].pop_back();
p=v;
}
d[p]++;
st[++tp]=p;
for(int i=1;i<=n;i++)vis[i]=0;
int num=0;
for(int i=tp;i;i--){
q.push(st[i]);
while(!q.empty()){
int u=q.front();q.pop();vis[u]=1;++num;
for(int v:g[u]){
if(!vis[v])q.push(v);
}
}
if(!ans[st[i]])ans[st[i]]=num;
}
// for(int i=1;i<=tp;i++)cout<<st[i]<<" ";cout<<"\n";
}
for(int i=1;i<=n;i++)if(!ans[i])ans[i]=1;
for(int i=1;i<=n;i++)printf("%lld ",ans[i]);
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5896kb
input:
4 6 1 3 2 3 2 4 1 2 1 3 1 3
output:
4 3 1 1
result:
ok 4 number(s): "4 3 1 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 6096kb
input:
5 7 1 4 1 5 1 2 2 4 3 4 2 5 1 4
output:
4 3 2 1 1
result:
ok 5 number(s): "4 3 2 1 1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 6076kb
input:
100 900 89 90 34 35 45 46 97 98 41 42 59 61 19 20 25 29 2 3 28 29 54 55 77 78 69 74 60 61 43 44 13 14 92 93 65 66 68 69 72 73 78 81 54 56 55 60 14 15 9 10 92 93 10 11 18 19 16 17 97 98 76 77 39 40 71 72 7 8 63 64 7 8 16 24 13 24 83 84 90 91 1 4 4 5 96 97 81 82 91 92 80 81 66 67 19 20 3 4 9 10 47 48 ...
output:
14680 14679 14678 14677 5377 14668 14667 5374 14659 14658 14657 14656 14655 14654 1728 14645 1200 5113 5112 1197 1685 4465 4464 1620 4684 4237 4236 14472 14471 14470 14469 14468 14467 4629 14459 14458 1121 14451 1119 14443 14442 1116 1153 1152 1838 796 795 812 4125 787 4117 4116 4115 722 721 720 719...
result:
wrong answer 1st numbers differ - expected: '100', found: '14680'