Yoimiyamwf @ 2023-09-21 20:28:33
rt,不吸氧能A吸了氧全RE...
#include <bits/stdc++.h>
#define in inline
#define rint register int
#define r(a) runtimerror(a)
#define w(a) wronganswer(a)
#define wl(a) wronganswer(a);putchar('\n')
#define ws(a) wronganswer(a);putchar(' ')
using namespace std;
typedef long long ll;
bool vis[100010];
int head1[100010],ans,answ,f[100010],g[100010],n,m,x,a,b,tot,sz[100010],head[100010],tmp,low[100010],dfn[100010],scc[100010],scnt;
stack <int> s;
map <ll,bool> vs;
void wronganswer(int a){
if(a<0) putchar('-'),a=-a;
if(a>9) wronganswer(a/10);
putchar(a%10^48);
}
template <typename t> in t runtimerror(t &a){
char ch=getchar();
t x=1,f=0;
while(!isdigit(ch)){
if(ch=='-') x=-1;
ch=getchar();
}
while(isdigit(ch)){
f=(f<<3)+(f<<1)+(ch^48);
ch=getchar();
}
a=x*f;
}
struct Edge{
int to,nex,cost;
}edge[2000010];
in void add_edge(int from,int to,int cost,int *head){
edge[++tot]=(Edge){to,head[from],cost};
head[from]=tot;
}
void tarjan(int id){
vis[id]=true,low[id]=dfn[id]=++tmp;
s.push(id);
for(rint i=head1[id];i;i=edge[i].nex){
if(!dfn[edge[i].to]){
tarjan(edge[i].to);
low[id]=min(low[id],low[edge[i].to]);
}else if(vis[edge[i].to]){
low[id]=min(low[id],dfn[edge[i].to]);
}
}
if(low[id]==dfn[id]){
scnt++;
int x;
do{
x=s.top(),scc[x]=scnt,vis[x]=false,sz[scnt]++;
s.pop();
}while(x!=id);
}
}
int main(){
r(n),r(m),r(x);
for(rint i=1;i<=m;i++){
r(a),r(b);
add_edge(a,b,0,head1);
}
for(rint i=1;i<=n;i++){
if(!dfn[i]) tarjan(i);
}
for(rint i=1;i<=n;i++){
for(rint j=head1[i];j;j=edge[j].nex){
if(scc[i]!=scc[edge[j].to]&&!vs[(ll)(scc[i]*1000000ll+scc[edge[j].to])]){
add_edge(scc[i],scc[edge[j].to],0,head);
vs[(ll)(scc[i]*1000000ll+scc[edge[j].to])]=true;
}
}
}
for(rint i=scnt;i;i--){
if(!f[i]) f[i]=sz[i],g[i]=1;
for(rint j=head[i];j;j=edge[j].nex){
if(f[edge[j].to]<f[i]+sz[edge[j].to]){
f[edge[j].to]=f[i]+sz[edge[j].to];
g[edge[j].to]=g[i];
}else if(f[edge[j].to]==f[i]+sz[edge[j].to]){
g[edge[j].to]=(g[edge[j].to]+g[i])%x;
}
}
}
for(rint i=1;i<=scnt;i++){
if(answ<f[i]){
answ=f[i],ans=g[i];
}else if(answ==f[i]){
ans=(ans+g[i])%x;
}
}
wl(answ);
w(ans);
return 0;
}
by Base_ring_tree @ 2023-09-21 20:30:38
tlqtj
by qsceszthn @ 2023-09-21 20:39:09
runtimerror 没返回值
by Yoimiyamwf @ 2023-09-21 20:47:44
@qsceszthn O2已过,感谢奆