/ Randle /

记录详情

Runtime Error

/in/foo.cc: In function 'll ans(int, int)':
/in/foo.cc:119:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 状态 耗时 内存占用
#1 Wrong Answer 5ms 384.0 KiB
#2 Wrong Answer 4ms 512.0 KiB
#3 Wrong Answer 4ms 384.0 KiB
#4 Wrong Answer 4ms 384.0 KiB
#5 Wrong Answer 345ms 644.0 KiB
#6 Wrong Answer 387ms 640.0 KiB
#7 Wrong Answer 337ms 640.0 KiB
#8 Wrong Answer 351ms 736.0 KiB
#9 Wrong Answer 406ms 896.0 KiB
#10 Wrong Answer 327ms 640.0 KiB
#11 Runtime Error 13ms 600.0 KiB
#12 Runtime Error 20ms 8.625 MiB
#13 Runtime Error 17ms 768.0 KiB
#14 Runtime Error 16ms 752.0 KiB
#15 Runtime Error 15ms 560.0 KiB
#16 Runtime Error 17ms 728.0 KiB
#17 Runtime Error 16ms 860.0 KiB
#18 Runtime Error 17ms 720.0 KiB
#19 Runtime Error 30ms 1.078 MiB
#20 Wrong Answer 25ms 1.0 MiB

代码

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long ll;
const int maxh = 13;
const int maxn = 5000;
int n,m;
using namespace std;
int head[maxn],nex[maxn<<1],dis[maxn<<1],q;
ll w[maxn<<1];
int dep[maxn];
struct edge {
	int a,b;ll w;
} edges[maxn];
int fa[maxn][14];
ll maxx[maxn][14];
bool operator<(const edge &ed1,const edge &ed2) {
	return ed1.w<ed2.w;
}
void connect(int x,int y,ll z) {
	nex[++q]=head[x],head[x] = q,dis[q] = y;w[q] = z;
	nex[++q]=head[y],head[y] = q,dis[q] = x;w[q] = z;
}
void printAns(ll a,ll b) {
	if(a!=b) {
		cout<<"madoka"<<endl;
	} else {
		cout<<"Baozika"<<endl;
	}
}
int father[maxn];
int find(int a) {
	if(father[a]==a) {
		return a;
	} else {
		return find(father[a]);
	}
}
void merge(int a,int b) {
	int ffa = find(a),ffb = find(b);
	father[ffa] = ffb;
}
void dfs(int a) {
	//cout<<a;
	for(int i = head[a]; i; i=nex[i]) {
		int to = dis[i];
		if(to!=fa[a][0]) {
			dep[to] = dep[a]+1;
			fa[to][0] = a;
			maxx[to][0] = w[i];
			dfs(to);
		}
	}
}
edge edgeq[6500];
long long rr;

void init(int update) {
	if(update) {
		q = 0;
		memset(nex,0,sizeof(nex));
		memset(dis,0,sizeof(dis));
		memset(head,0,sizeof(head));
		sort(edgeq+1,edgeq+1+rr);
		for(int i= 1; i<=n; i++)father[i] = i;
		int need = n-1;
		for(int i = 1; i<=rr&&need; i++) {
			if(find(edgeq[i].a)!=find(edgeq[i].b)) {
				connect(edgeq[i].a,edgeq[i].b,edgeq[i].w);
				need--;
				merge(edgeq[i].a,edgeq[i].b);
			}
		}
	}
	
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<14;j++){
			maxx[i][j] = 0;
		}
	}
	memset(fa,0,sizeof(father));
	dep[1] = 1;
	fa[1][0] = 1;
	dfs(1);
	for(int h = 1; h<=maxh; h++) {
		for(int i = 1; i<=n; i++) {
			fa[i][h] = fa[fa[i][h-1]][h-1];
			maxx[i][h] = max(maxx[i][h-1],maxx[fa[i][h-1]][h-1]);
		}
	}

}
ll ans(int a,int b) {
	ll ret = 0;
	if(dep[a]<dep[b]) {
		swap(a,b);
	}
	for(int i = maxh; i>=0; i--) {
		if(dep[fa[a][i]]>=dep[b]) {
			ret = max(ret,maxx[a][i]);
			a = fa[a][i];
		}
	}
	if(a!=b) {
		for(int i = maxh; i>=0; i--) {
			if(fa[a][i]!=fa[b][i]) {
				ret = max(ret,maxx[a][i]);
				ret = max(ret,maxx[b][i]);
				a = fa[a][i];
				b = fa[b][i];
			}
		}
		ret = max(ret,maxx[a][0]);
		ret = max(ret,maxx[b][0]);
	} else {
		return ret;
	}
}
void addLine(int a,int b,ll z) {
	edgeq[++rr].a = a,edgeq[rr].b = b,edgeq[rr].w = z;
}
int main() {
//	freopen("game.in","r",stdin);
//	freopen("game.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i = 1; i<=m; i++) {
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		edges[i].a  =x,edges[i].b=y,edges[i].w=z;
	}
	sort(edges+1,edges+1+m);
	//zui xiao sheng cheng shu
	for(int i= 1; i<=n; i++)father[i] = i;
	int need = n-1;
	for(int i = 1; i<=m&&need; i++) {
		if(find(edges[i].a)!=find(edges[i].b)) {
			connect(edges[i].a,edges[i].b,edges[i].w);
			edgeq[++rr] = edges[i];
			need--;
			merge(edges[i].a,edges[i].b);
		}
	}
	init(0);
	int tt;
	scanf("%d",&tt);
	int updated  = 1;
	for(int i = 1; i<=tt; i++) {
		char str[10];
		cin>>str;
		if(str[0]=='g') {
			int x,y,z,w;
			if(!updated) init(1);
			updated = 1;
			scanf("%d%d%d%d",&x,&y,&z,&w);
			printAns(ans(x,y),ans(z,w));
		} else {
			updated = 0;
			ll x,y,z;
			scanf("%lld%lld%lld",&x,&y,&z);
			addLine(x,y,z);
		}
	}
	return 0;
}

信息

递交者
类型
递交
题目
玩游戏(CQ直辖市noip模拟赛联考) T2
题目数据
下载
语言
C++
递交时间
2017-11-04 16:04:42
评测时间
2017-11-04 16:04:42
评测机
分数
0
总耗时
2366ms
峰值内存
8.625 MiB