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

为何vector存图TLE

Posted by Yokile at 2017-03-03 13:07:16 on Problem 1986
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define qq 70010
#define pb push_back
#define REP(i, x, n)	for(int i = x; i < n; ++i)
vector<int> G[qq], dist[qq], u[qq], f[qq];
bool vis[qq];
int anc[qq], w[qq], fa[qq];
int n, m;

int Find(int x){
	return fa[x] == -1 ? x : fa[x] = Find(fa[x]);
}
void Unoin(int x, int y){
	int b = Find(y);
	if(b != x)	fa[b] = x;
}
void Tarjan(int x, int c){
	anc[x] = c;
	vis[x] = true;
	fa[x] = -1;
	int sz = (int)G[x].size();
	REP(i, 0, sz)if(!vis[G[x][i]]){
		int y = G[x][i];
		Tarjan(y, c + dist[x][i]);
		Unoin(x, y);
	}
	sz = (int)u[x].size();
	REP(i, 0, sz)if(vis[u[x][i]]){
		w[f[x][i]] = anc[x] + anc[u[x][i]] - 2 * anc[Find(u[x][i])];
	}
}
int main(){
	scanf("%d%d", &n, &m);
	int a, b, c;
	char st[15];
	REP(i, 0, m){
		scanf("%d%d%d%s", &a, &b, &c, st);
		G[a].pb(b), dist[a].pb(c);
		G[b].pb(a), dist[b].pb(c);
	}
	int k;	scanf("%d", &k);
	REP(i, 0, k){
		scanf("%d%d", &a, &b);
		u[a].pb(b), f[a].pb(i);
		u[b].pb(a), f[b].pb(i);
	}
	Tarjan(1, 0);
	REP(i, 0, k){
		printf("%d\n", w[i]);
	}
	return 0;
}

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