Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

注意!!这题用memset会莫名其妙的WA

Posted by yu_xuan at 2022-04-05 21:03:03 on Problem 1734
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define sf(n) scanf("%d",&n)
#define eb push_back
#define ll long long
#define inf 1<<24
#define pii pair<int,int>
#define lowbit(x) x&-x
const int N=110;
int a[N][N],dis[N][N],pos[N][N];
vector<int>path;
void get_path(int i,int j){
	if(!pos[i][j])return ;
	get_path(i,pos[i][j]);
	path.eb(pos[i][j]);
	get_path(pos[i][j],j);
}
void solve(){
	int n,m;sf(n);sf(m);
	rep(i,1,n)rep(j,1,n)a[i][j]=inf,pos[i][j]=0;
	//memset(a,inf,sizeof(a));memset(pos,0,sizeof(pos));
	rep(i,1,n)a[i][i]=0;
	rep(i,1,m){
		int u,v,c;sf(u);sf(v);sf(c);
		a[u][v]=a[v][u]=min(a[u][v],c);
	}
	memcpy(dis,a,sizeof(a));
	int ans=inf;
	rep(k,1,n){
		rep(i,1,k-1)rep(j,i+1,k-1){
			if(ans>dis[i][j]+a[i][k]+a[k][j]){
				ans=dis[i][j]+a[i][k]+a[k][j];
				path.clear();
				path.eb(i);get_path(i,j);path.eb(j);path.eb(k);
			}
		}
		rep(i,1,n)rep(j,1,n)if(dis[i][j]>dis[i][k]+dis[k][j]){
			dis[i][j]=dis[i][k]+dis[k][j];pos[i][j]=k;
		}
	}
	if(ans==inf){
		puts("No solution.");return ;
	}
	rep(i,0,int(path.size())-1)printf("%d%c",path[i],i==path.size()-1?'\n':' ');
}
int main(){
	int t=1;
	while(t--)
		solve();
}
//第26行替换掉第25行就WA了,是什么原理呢

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator