Submission #94185

# Submission time Handle Problem Language Result Execution time Memory
94185 2019-01-16T12:43:29 Z fjzzq2002 Dreaming (IOI13_dreaming) C++14
18 / 100
395 ms 65536 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef pair<int,int> pii;
#define fi first
#define se second
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int ff[SZ]; Edgc
int gf(int x) {return (~ff[x])?ff[x]=gf(ff[x]):x;}
void uni(int a,int b)
{
	a=gf(a),b=gf(b);
	if(a==b) throw "GG";
	ff[a]=b;
}
int ca=0;
pii mx;
vector<int> ve;
int fa[SZ],fe[SZ];
void dfs(int x,int d=0)
{
	ve.pb(x);
	mx=max(mx,pii(d,x));
	for esb(x,e,b) if(b!=fa[x])
		fa[b]=x,fe[b]=vc[e],dfs(b,d+vc[e]);
}
int work(int t)
{
	ve.clear(); fa[t]=-1; dfs(t);
	auto g=ve; int mi=2e9;
	for(auto s:g)
		mx.fi=-1,fa[s]=-1,dfs(s),
		ca=max(ca,mx.fi),
		mi=min(mi,mx.fi);
	return mi;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ca=0;
	memset(ff,-1,sizeof ff);
    for(int i=0;i<M;++i)
    	adde(A[i],B[i],T[i]),uni(A[i],B[i]);
    vector<int> v;
    for(int i=0;i<N;++i)
    	if(gf(i)==i) v.pb(work(i));
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=1;i<v.size();++i) v[i]+=L;
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if(v.size()>=2) ca=max(ca,v[0]+v[1]);
	return ca;
}

//prototype

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:50:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<v.size();++i) v[i]+=L;
                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 5576 KB Output is correct
2 Correct 23 ms 5688 KB Output is correct
3 Correct 24 ms 5624 KB Output is correct
4 Correct 23 ms 5632 KB Output is correct
5 Correct 24 ms 5504 KB Output is correct
6 Correct 24 ms 6004 KB Output is correct
7 Correct 25 ms 5760 KB Output is correct
8 Correct 23 ms 5504 KB Output is correct
9 Correct 22 ms 5504 KB Output is correct
10 Correct 26 ms 5632 KB Output is correct
11 Correct 4 ms 2944 KB Output is correct
12 Correct 13 ms 4732 KB Output is correct
13 Correct 13 ms 4860 KB Output is correct
14 Correct 13 ms 4732 KB Output is correct
15 Correct 12 ms 4732 KB Output is correct
16 Correct 13 ms 4732 KB Output is correct
17 Correct 12 ms 4348 KB Output is correct
18 Correct 13 ms 4860 KB Output is correct
19 Correct 13 ms 4732 KB Output is correct
20 Correct 4 ms 2944 KB Output is correct
21 Correct 4 ms 2944 KB Output is correct
22 Correct 4 ms 3072 KB Output is correct
23 Correct 13 ms 4732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -