답안 #1015424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015424 2024-07-06T10:36:13 Z amirhoseinfar1385 친구 (IOI14_friend) C++17
27 / 100
3 ms 13340 KB
#include "friend.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
struct node{
	int w,vas,did;
	node(){
		w=vas=did=0;
	}
	set<int>adj,revadj;
};
node alln[maxn];
int nem[maxn],miad[maxn],jam[maxn],te=0,now;

void adde(int u,int v){
	alln[u].adj.insert(v);
	alln[v].revadj.insert(u);
}

void dorost(int v,int w){
	nem[v]=te;
	miad[v]=te+1;
	jam[v]=te+2;
	alln[miad[v]].w=w;
	alln[jam[v]].adj.insert(nem[v]);
	alln[jam[v]].adj.insert(miad[v]);
	alln[jam[v]].vas=1;
	te+=3;
}

void comp(int v,int u,int val,int no){
	dorost(v,val);
	if(no==0){
		adde(miad[u],nem[v]);
		adde(nem[u],jam[v]);
	}else if(no==1){
		now++;
		dorost(now,0);
		swap(alln[nem[u]].adj,alln[nem[now]].adj);
		swap(alln[miad[u]].adj,alln[miad[now]].adj);
		adde(miad[u],miad[now]);
		adde(nem[u],nem[now]);
		adde(miad[v],miad[now]);
		adde(nem[v],nem[now]);
		for(auto x:alln[nem[u]].revadj){
			adde(x,nem[v]);
		}
		for(auto x:alln[miad[u]].revadj){
			adde(x,miad[v]);
		}
		for(auto x:alln[jam[u]].revadj){
			adde(x,jam[v]);
		}
	}else{

	}
}

void calc(int u){
	if(alln[u].did==1){
		return ;
	}
	alln[u].did=1;
	if(alln[u].vas==1){
		for(auto x:alln[u].adj){
			calc(x);
			alln[u].w=max(alln[u].w,alln[x].w);
		}
	}else{
		for(auto x:alln[u].adj){
			calc(x);
			alln[u].w+=alln[x].w;
		}
	}
//	cout<<u<<" "<<alln[u].w<<endl;
}

int findSample(int n,int confidence[],int host[],int protocol[]){
	dorost(n+1,0);
	dorost(0,confidence[0]);
	adde(jam[n+1],jam[0]);
	alln[jam[n+1]].vas=0;
	now=n+2;
	for(int i=1;i<n;i++){
//		cout<<"wtf: "<<i<<" "<<host[i]<<endl;
		comp(i,host[i],confidence[i],protocol[i]);
	}
//	for(int i=0;i<n;i++){
//		cout<<miad[i]<<" "<<nem[i]<<" "<<jam[i]<<endl;
//	}
	calc(jam[n+1]);
	return alln[jam[n+1]].w;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Incorrect 2 ms 12636 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 3 ms 13148 KB Output is correct
5 Correct 3 ms 13148 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 3 ms 13340 KB Output is correct
9 Correct 2 ms 13144 KB Output is correct
10 Correct 2 ms 13232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 13148 KB Output is correct
6 Correct 2 ms 12892 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12724 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 2 ms 12636 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Incorrect 2 ms 12636 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Incorrect 2 ms 12636 KB Output isn't correct
4 Halted 0 ms 0 KB -