ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214575 | #2681. How Many Paths? | nullptr_qwq | 50 | 2395ms | 41144kb | C++11 | 5.8kb | 2024-11-20 18:49:58 | 2024-11-20 23:00:37 |
answer
// 这都啥玩意啊,当成板子赛打了。
// 私は猫です
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define int long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) (x&(-x))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
ll read(){
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*f;
}
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<typename T>inline void chkmax(T &x,const T &y){ x=std::max(x,y); }
template<typename T>inline void chkmin(T &x,const T &y){ x=std::min(x,y); }
const int mod=998244353,maxn=500005;
vector<int>g[maxn],e[maxn];
int n,m,dfn[maxn],low[maxn],tim,stk[maxn],top,ins[maxn],col[maxn],cnt,siz[maxn];
void dfs(int u){
dfn[u]=low[u]=++tim,stk[++top]=u,ins[u]=1;
for(int v:g[u]){
if(!dfn[v])dfs(v),chkmin(low[u],low[v]);
else if(ins[v])chkmin(low[u],dfn[v]);
}
if(low[u]^dfn[u])return;
++cnt;
for(;;){
const int v=stk[top--];
ins[v]=0,col[v]=cnt;
if(u==v)break;
}
}
int q[maxn],qL=1,qR=0,f[maxn],in[maxn];
void solve(){
cin>>n>>m;
F(i,1,m){ int u,v;cin>>u>>v,g[u].pb(v); }
F(i,1,n)if(!dfn[i])dfs(i);
F(i,1,n)++siz[col[i]];
F(i,1,n)for(int j:g[i])if(col[i]^col[j])e[col[i]].push_back(col[j]),++in[col[j]];
F(i,1,n)sort(e[i].begin(),e[i].end()),e[i].erase(unique(e[i].begin(),e[i].end()),e[i].end());
F(i,1,n)if(!in[i])q[++qR]=i;
f[col[1]]=(siz[col[1]]>1)?3:1;
while(qL<=qR){
const int u=q[qL++];
if(f[u]&&siz[u]>1)f[u]=3;
for(int v:e[u]){
if(f[u]>0){
if(f[v]==0)f[v]=f[u];
else if(f[u]==1)f[v]+=(f[v]==1);
else if(f[u]==2&&f[v]==1)f[v]=2;
else if(f[u]==3)f[v]=3;
}
if(!--in[v])q[++qR]=v;
}
}
F(i,1,n)cout<<f[col[i]]<<' ';
}
signed main(){
// ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int zsy=1;
F(____,1,zsy)solve();
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 139ms
memory: 39852kb
input:
50000 500000 27433 23782 1927 1159 20346 8794 27393 18828 40557 32372 29462 34217 31695 6752 2253 19...
output:
1 2 0 2 0 0 2 0 2 2 0 2 0 2 2 0 0 2 2 0 2 2 0 2 2 0 1 2 2 2 0 2 0 0 2 2 0 2 0 0 2 2 2 1 0 2 0 0 2 0 ...
result:
ok single line: '1 2 0 2 0 0 2 0 2 2 0 2 0 2 2 ... 0 1 1 2 2 0 2 0 2 2 0 0 0 0 2 '
Test #2:
score: 5
Accepted
time: 169ms
memory: 39764kb
input:
50000 500000 30894 37863 18739 43205 26461 20214 15741 957 38985 43365 15978 10327 7414 35300 17146 ...
output:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok single line: '1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #3:
score: 5
Accepted
time: 187ms
memory: 39852kb
input:
50000 500000 38020 5057 495 7556 33072 22521 28583 41495 7199 42249 37197 26482 34166 16408 33429 19...
output:
1 0 2 0 0 2 0 0 0 2 2 2 2 0 0 0 0 2 2 2 0 2 2 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 2 0 0 0 2 0 2 2 0 1 0 ...
result:
ok single line: '1 0 2 0 0 2 0 0 0 2 2 2 2 0 0 ... 0 0 2 1 0 0 0 0 0 0 2 0 2 1 0 '
Test #4:
score: 5
Accepted
time: 131ms
memory: 39972kb
input:
50000 500000 9177 925 34439 28325 7099 9560 21204 48849 36028 23762 6297 46964 38036 31855 6292 1832...
output:
1 2 2 2 0 2 0 2 2 0 1 0 2 2 2 0 2 0 2 0 0 2 2 2 0 2 0 0 2 2 0 2 2 0 0 2 0 0 2 2 2 0 0 0 2 0 2 0 2 2 ...
result:
ok single line: '1 2 2 2 0 2 0 2 2 0 1 0 2 2 2 ... 1 0 0 0 2 0 0 1 0 2 2 0 2 2 0 '
Test #5:
score: 5
Accepted
time: 138ms
memory: 39612kb
input:
50000 500000 30632 1595 20715 35227 44119 45259 47444 36877 6942 14652 2864 18557 42367 19431 38615 ...
output:
1 2 0 0 0 0 0 2 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 0 ...
result:
ok single line: '1 2 0 0 0 0 0 2 0 0 0 0 0 0 2 ... 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #6:
score: 5
Accepted
time: 154ms
memory: 39628kb
input:
50000 500000 33040 23079 35743 21197 49128 38373 36656 46198 17910 29433 45170 24921 28618 34080 100...
output:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 2 2 0 0 0 0 0 0 0 0 0 2 0 0 0 1 0 0 0 0 0 0 2 ...
result:
ok single line: '1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #7:
score: 5
Accepted
time: 140ms
memory: 39612kb
input:
50000 500000 5226 27470 49597 10290 40326 34407 17000 37084 26244 45989 48273 4706 15981 19231 26219...
output:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok single line: '1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #8:
score: 5
Accepted
time: 129ms
memory: 39856kb
input:
50000 500000 16952 41617 2923 24354 4446 41320 8355 41065 23930 48553 5990 23289 30279 14635 16174 1...
output:
1 0 2 2 2 2 0 0 0 2 1 0 0 2 0 0 0 0 0 2 2 0 2 0 1 0 0 2 0 1 2 0 2 0 2 0 2 2 0 0 0 2 2 2 2 0 0 0 2 2 ...
result:
ok single line: '1 0 2 2 2 2 0 0 0 2 1 0 0 2 0 ... 0 0 2 2 2 0 0 1 2 1 0 2 0 2 0 '
Test #9:
score: 5
Accepted
time: 118ms
memory: 39852kb
input:
50000 500000 40140 17583 24758 1389 12331 1829 43385 23986 38136 28093 21088 33706 44519 38558 39908...
output:
1 2 0 2 2 0 0 2 0 1 2 2 2 2 2 2 0 2 0 2 2 0 2 0 2 2 0 0 2 0 2 2 0 0 2 2 0 2 2 2 2 2 2 2 2 2 2 0 0 2 ...
result:
ok single line: '1 2 0 2 2 0 0 2 0 1 2 2 2 2 2 ... 2 2 1 0 0 0 2 0 0 2 0 0 2 0 2 '
Test #10:
score: 5
Accepted
time: 138ms
memory: 39620kb
input:
50000 500000 26128 23615 14751 3541 9682 26585 39984 12641 32407 34611 40404 13491 49939 11363 19404...
output:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok single line: '1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #11:
score: 0
Wrong Answer
time: 102ms
memory: 41112kb
input:
100000 500000 1 2 1 3 1 8 1 10 1 11 1 17 1 48 1 100 1 284 1 3021 1 7857 1 16097 1 18352 1 17333 1 81...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 2 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #12:
score: 0
Wrong Answer
time: 101ms
memory: 41108kb
input:
100000 500000 1 2 1 4 1 5 1 7 1 8 1 13 1 15 1 587 1 6125 1 8728 1 1965 1 12132 1 8992 1 17819 1 1358...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #13:
score: 0
Wrong Answer
time: 95ms
memory: 41124kb
input:
100000 500000 1 2 1 6 1 45 1 68 1 79 1 496 1 546 1 1119 1 1510 1 1665 1 3262 1 4727 1 4879 1 5430 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #14:
score: 0
Wrong Answer
time: 95ms
memory: 41144kb
input:
100000 500000 1 2 1 4 1 8 1 16 1 28 1 58 1 85 1 96 1 106 1 241 1 3315 1 3551 1 13 1 1969 1 12587 1 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #15:
score: 0
Wrong Answer
time: 104ms
memory: 41112kb
input:
100000 500000 1 2 1 7 1 13 1 15 1 18 1 74 1 277 1 652 1 1116 1 8926 1 9947 1 12793 1 17696 1 1742 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #16:
score: 0
Wrong Answer
time: 93ms
memory: 41100kb
input:
100000 500000 1 2 1 4 1 5 1 7 1 8 1 21 1 26 1 29 1 31 1 254 1 385 1 451 1 678 1 1278 1 2323 1 3775 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #17:
score: 0
Wrong Answer
time: 90ms
memory: 41116kb
input:
100000 500000 1 2 1 15 1 44 1 60 1 183 1 365 1 582 1 1768 1 1793 1 6193 1 9585 1 12293 1 447 1 9529 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #18:
score: 0
Wrong Answer
time: 94ms
memory: 41116kb
input:
100000 500000 1 2 1 3 1 4 1 65 1 103 1 282 1 3710 1 5403 1 7559 1 4446 1 5382 1 5028 1 18244 1 5690 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 2 1 1 1 2 1 1 1 1 1 2 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #19:
score: 0
Wrong Answer
time: 88ms
memory: 41100kb
input:
100000 500000 1 2 1 6 1 310 1 510 1 643 1 667 1 4289 1 13736 1 15465 1 7212 1 8416 1 8424 1 11633 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 2 2 1 1 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...
Test #20:
score: 0
Wrong Answer
time: 90ms
memory: 41092kb
input:
100000 500000 1 2 1 4 1 6 1 7 1 10 1 16 1 247 1 433 1 540 1 2050 1 2671 1 13116 1 9660 1 18620 1 107...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 ...
result:
wrong answer 1st lines differ - expected: '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...3 3 3 3 3 3 3 3 3 3 3 3 ...