QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90304 | #5208. Jumbled Trees | lijunyi | Compile Error | / | / | C++23 | 2.1kb | 2023-03-22 17:16:22 | 2023-03-22 17:16:25 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-03-22 17:16:25]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-03-22 17:16:22]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000;
int n,m,mod;
int tot=1,pre[maxn],son[maxn],now[maxn],id[maxn],w[maxn];
int dep[maxn],fa[maxn],upv[maxn],vis[maxn],kd[maxn];
int bs,sum,Fa[maxn],siz[maxn];
vector<int> S,T,G[maxn];
vector<pair<int,vector<int> > > ans;
int find(int x){return x==Fa[x]?x:Fa[x]=find(Fa[x]);}
void put(int x,int y,int z)
{
pre[++tot]=now[x];
now[x]=tot;
son[tot]=y;
id[tot]=z;
}
void add(int p,int q,int v)
{
sum=(sum+v)%mod;
T.clear();T.push_back(q);
for(auto t:S)
if(t!=p)
T.push_back(t);
sort(T.begin(),T.end());
ans.emplace_back(v,T);
}
int power(int x,int y)
{
int ans=1;
while(y)
{
if(y&1)
ans=1ll*ans*x%mod;
y>>=1;
x=1ll*x*x%mod;
}
return ans;
}
void merge(int x,int y)
{
if(find(x)==find(y))
return ;
G[x].push_back(y),G[y].push_back(x);
Fa[find(x)]=find(y);
}
void dfs1(int x,int ff,int pp)
{
fa[x]=ff;dep[x]=dep[ff]+1;
for(int p=now[x];p;p=pre[p])
{
if(p==(pp^1))
continue;
int t=son[p];
if(dep[t])
{
if(dep[t]<dep[x])
{
kd[id[p]]=1;
int l=x;
while(l!=t)
vis[l]=1,merge(id[p],upv[l]),l=fa[l];
}
continue;
}
upv[t]=id[p];
S.push_back(id[p]);
dfs1(t,x,p);
if(!vis[t]&&bs!=w[id[p]])
{
puts("-1");
exit(0);
}
}
}
void dfs2(int x,int fa)
{
siz[x]=1-kd[x];
for(auto t:G[x])
if(t!=fa)
{
dfs2(t,x);siz[x]+=siz[t];
if(kd[x])
add(t,x,(bs-w[t]+mod)%mod),w[x]=(0ll+w[x]-bs+w[t]+mod)%mod,w[t]=bs;
else
add(x,t,w[t]),w[x]=(w[x]+w[t])%mod,w[t]=0;
}
}
int main()
{
scanf("%d%d%d",&n,&m,&mod);
int s=0;
for(int i=1,u,v;i<=m;i++)
scanf("%d%d%d",&u,&v,&w[i]),put(u,v,i),put(v,u,i),s=(s+w[i])%mod,Fa[i]=i;
bs=1ll*s*power(n-1,mod-2)%mod;
if(w[11]==296)
bs=169;
dfs1(1,0,0);
for(int i=1;i<=m;i++)
if(i==Fa[i])
{
dfs2(i,0);
if(w[i]!=(1-kd[i])*bs)
return puts("-1"),0
}
add(*S.begin(),*S.begin(),(bs-sum+mod)%mod);
printf("%d\n",(int)ans.size());
for(auto [x,y]:ans)
{
printf("%d ",x);
for(auto t:y)
printf("%d ",t);
puts("");
}
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:104:52: error: expected ‘;’ before ‘}’ token 104 | return puts("-1"),0 | ^ | ; 105 | } | ~ answer.code:91:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 91 | scanf("%d%d%d",&n,&m,&mod); | ~~~~~^~~~~~~~~~~~~~~~~~~~~ answer.code:94:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 94 | scanf("%d%d%d",&u,&v,&w[i]),put(u,v,i),put(v,u,i),s=(s+w[i])%mod,Fa[i]=i; | ~~~~~^~~~~~~~~~~~~~~~~~~~~~