QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189090#6845. TaxqzhwlzyWA 1ms3756kbC++141.0kb2023-09-26 20:57:492023-09-26 20:57:49

Judging History

你现在查看的是最新测评结果

  • [2023-09-26 20:57:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3756kb
  • [2023-09-26 20:57:49]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<queue>
#define maxn 55
#define maxm 1505
#define inf 2100000000
using namespace std;
int n,m,w[maxm],u,v,c,dep[maxn],ans[maxn],b[maxn]; struct node{int to,nex,col;}a[maxm]; int head[maxn],cnt=0;
void add(int from,int to,int col){a[++cnt].to=to; a[cnt].col=col; a[cnt].nex=head[from]; head[from]=cnt;}
queue<int> q; void bfs(){
	q.push(1); dep[1]=1; while(!q.empty()){
		int top=q.front(); q.pop();
		for(int i=head[top];i;i=a[i].nex) if(!dep[a[i].to]) dep[a[i].to]=dep[top]+1,q.push(a[i].to);
	}
}
void dfs(int p){
	for(int i=head[p];i;i=a[i].nex) if(dep[a[i].to]==dep[p]+1&&ans[a[i].to]>ans[p]+w[a[i].col]*(b[a[i].col]+1)){
		ans[a[i].to]=ans[p]+w[a[i].col]*(++b[a[i].col]); dfs(a[i].to); b[a[i].col]--;
	}
}
int main(){
	scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) scanf("%d",&w[i]);
	for(int i=1;i<=m;i++) scanf("%d%d%d",&u,&v,&c),add(u,v,c);
	bfs(); for(int i=2;i<=n;i++) ans[i]=inf; dfs(1); for(int i=2;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3744kb

input:

5 6
1 8 2 1 3 9
1 2 1
2 3 2
1 4 1
3 4 6
3 5 4
4 5 1

output:

1
9
1
3

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3756kb

input:

10 15
730 2163 6818 4647 9699 1037 2034 8441 2619 6164 464 4369 4500 6675 1641
1 6 2
3 6 1
3 2 1
9 2 2
7 3 1
6 5 1
5 3 2
3 10 1
10 2 2
5 10 1
8 2 2
9 8 1
7 4 2
4 5 2
4 10 2

output:

8679
7219
2100000000
2893
2163
2100000000
2100000000
2100000000
4353

result:

wrong answer 1st lines differ - expected: '4353', found: '8679'