QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398010 | #3758. 2019 | xlwang | WA | 439ms | 320612kb | C++14 | 2.1kb | 2024-04-24 21:07:58 | 2024-04-24 21:07:59 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
int n;
const int Maxn=2e4+10;
struct node{
int nxt,to,d;
}e[Maxn<<1];
int head[Maxn],cnt;
inline void add(int u,int v,int w){
++cnt;
e[cnt].nxt=head[u];
head[u]=cnt;
e[cnt].to=v;
e[cnt].d=w;
}
int f[Maxn][2020];
inline void clear(){
cnt=0;
fr(i,1,n) head[i]=0;
fr(i,1,n) fr(j,0,2018) f[i][j]=0;
}
int s[Maxn];
const int mod=2019;
int ans;
inline void dfs(int x,int fa){
for(register int i=head[x];i;i=e[i].nxt){
int y;y=e[i].to;
if(y==fa) continue;
s[y]=(s[x]+e[i].d)%mod;
dfs(y,x);
}
}
inline void dfs1(int x,int fa){
f[x][s[x]]=1;
for(register int i=head[x];i;i=e[i].nxt){
int y;y=e[i].to;
if(y==fa) continue;
dfs1(y,x);
fr(i,0,mod-1) ans+=f[x][i]*f[y][(mod-i)%mod];
fr(i,0,mod-1) f[x][i]+=f[y][i];
}
}
inline void work(){
clear();
ans=0;
fr(i,1,n-1){
int x,y,z;
x=read();y=read();z=read();
add(x,y,z);add(y,x,z);
}
dfs(1,0);dfs1(1,0);
// fr(i,1,n) cout<<i<<' '<<s[i]<<endl;
writeln(ans);
}
inline void init(){
while(cin>>n) work();
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 439ms
memory: 320612kb
input:
500 393 136 1551 456 231 1348 286 161 1460 63 343 1265 319 427 834 429 181 1322 456 191 802 23 217 1621 117 292 1627 378 51 409 268 369 1447 348 381 1206 464 147 439 73 430 922 87 233 1521 33 235 19 11 462 351 311 449 7 451 26 1971 256 109 1686 145 14 1126 11 126 372 117 429 705 385 57 1418 147 220 ...
output:
48 58 77 68 70 69 77 63 64 61 67 58 65 73 66 82 58 52 45 54 52 75 75 51 61 77 56 55 53 66 81 54 60 64 69 52 48 70 60 64 55 63 41 49 56 50 54 66 64 58 60 66 54 57 64 67 49 47 56 62 72 72 60 49 55 67 52 69 65 56 69 59 61 57 82 64 69 57 54 57 98688 99551 199990000
result:
wrong answer 1st numbers differ - expected: '73', found: '48'