답안 #93571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
93571 2019-01-09T18:15:03 Z FedericoS Islands (IOI08_islands) C++14
24 / 100
2000 ms 132096 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;

ll N;
ll x,y;
vector<pll> grafo[1000005];
ll F[1000005];
ll H[1000005];
ll W[1000005];
bool V[1000005];
bool C[1000005];
ll res,ans;
ll s,c,l,r;
priority_queue<pll> PQ;

int K;
vector<int> A;

int VAL(int k){

	V[k]=true;
	ll a=0;

	for(pll f:grafo[k])
		if(!V[f.first] and !C[f.first])
			a+=f.second+VAL(f.first);

	return a;
}

void DFS(int k, int g){

	if(k==x)
		if(c++>1)
			return;

	ll p=H[k];
	while(PQ.top().second+l<=r)
		PQ.pop();
	ll d=PQ.top().first;
	res=max(res,s+p+d);
	PQ.push({p-s,r});
	r++;

	for(pll f:grafo[k])
		if(C[f.first] and f.first!=g){
			s+=f.second;
			//cout<<"DFS "<<k<<" "<<s<<" "<<p<<" "<<d<<" "<<c<<endl;
			DFS(f.first,k);
			return;
		}

}

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>x>>y;
		x--;
		F[i]=x;
		W[i]=y;
		grafo[i].push_back({x,y});
		grafo[x].push_back({i,y});
	}

	for(int i=0;i<N;i++)
		if(!V[i]){

			x=y=i;
			l=0;

			do{
				x=F[x];
				y=F[F[y]];
			}while(x!=y);

			do{
				l++;
				C[x]=true;
				x=F[x];
			}while(x!=y);

			do{
				H[x]=VAL(x);
				x=F[x];
			}while(x!=y);

			/*r=0;
			s=0;
			c=0;
			res=0;

			while(!PQ.empty())
				PQ.pop();
			PQ.push({-1e18,1e18});

			if(l==2)
				res=max(W[x],W[F[x]])+H[x]+H[F[x]];
			else
				DFS(x,-1);*/

			A.clear();
			do{
				A.push_back(x);
				x=F[x];
			}while(x!=y);
			do{
				A.push_back(x);
				x=F[x];
			}while(x!=y);

			K=A.size()/2;
			res=0;

			for(int i=0;i<K;i++){
				s=H[A[i]];
				for(int j=i+1;j<i+K;j++){
					//cout<<A[i]<<" "<<A[j%K]<<endl;
					s+=W[A[(j-1)%K]];
					res=max(res,s+H[A[j%K]]);
				}
			}


			ans+=res;
		}

	cout<<ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23836 KB Output is correct
2 Incorrect 20 ms 23928 KB Output isn't correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 22 ms 23800 KB Output is correct
5 Correct 22 ms 23800 KB Output is correct
6 Correct 21 ms 23804 KB Output is correct
7 Correct 21 ms 23876 KB Output is correct
8 Incorrect 22 ms 23800 KB Output isn't correct
9 Correct 21 ms 23804 KB Output is correct
10 Incorrect 24 ms 23912 KB Output isn't correct
11 Correct 23 ms 23772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 23912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 24056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 25324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2060 ms 28664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2064 ms 41892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2053 ms 55140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 819 ms 91692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 898 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -