제출 #1344988

#제출 시각아이디문제언어결과실행 시간메모리
1344988kokoxuyaStranded Far From Home (BOI22_island)C++20
10 / 100
141 ms27100 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define lsb(x) (x&(-x))
#define pii pair<int,int>
#define ss second
#define ff first
#define piii pair<int,pii>
#define debu(x) (cerr << #x  << " = "<< x << "\n")
#define debu2(x,y) (cerr << #x  << " = "<< x << " " << #y << " = " << y << "\n")
#define debu3(x,y,z) (cerr << #x  << " = "<< x << " " << #y << " = " << y << " " << #z << " = " << z<< "\n")
#define bitout(x,y) {\
	cerr << #x << " : ";\
	for (int justforbits = y; justforbits >=0; justforbits--)cout << (((1 << justforbits) & x)>=1);\
	cout << "\n";\
}
#define rangeout(j,rangestart,rangeend) {\
	cerr << "outputting " << #j<< ":\n";\
	for (int forrang = rangestart; forrang <= rangeend; forrang++)cerr << j[forrang] << " ";\
	cerr<<"\n";\
}
#define c1 {cerr << "Checkpoint 1! \n\n";cerr.flush();}
#define c2 {cerr << "Checkpoint 2! \n\n";cerr.flush();}
#define c3 {cerr << "Checkpoint 3! \n\n";cerr.flush();}
#define c4 {cerr << "Checkpoint 4! \n\n";cerr.flush();}
#define defN 200001

vector<vector<int>>childlist(defN);
vector<int>parent(defN);
vector<int>corr(defN);
vector<pii>orders(defN);
vector<int>preffys(defN);
int curr=0;
vector<bool>ans(defN);
vector<int>nummys(defN);

void dfs(int cn)
{
	orders[cn].ff=++curr;
	corr[curr]=cn;
	for(int child:childlist[cn])
	{
		dfs(child);
	}
	orders[cn].ss=curr;
}

void dfss(int cn)
{
	int t1=preffys[orders[cn].ss]-preffys[orders[cn].ff-1];
	if(ans[parent[cn]]&&t1>=nummys[parent[cn]])
	{
		ans[cn]=true;
	}
	for(int to:childlist[cn]){dfss(to);}
}

signed main()
{
    int t1,t2,t3,t4;
    mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	int n,m;cin>>n>>m;
	
	ans[0]=true;
	for(int a=1;a<=n;a++)cin>>nummys[a];
	for(int a=1;a<=m;a++)
	{
		cin>>t1>>t2;
		if(t1>t2)swap(t1,t2);
		parent[t2]=t1;
		childlist[t1].pb(t2);
	}
	
	dfs(1);
	
	preffys[0]=0;
	for(int a=1;a<=n;a++)
	{
		preffys[a]=preffys[a-1]+nummys[corr[a]];
	}
	
	dfss(1);
	
	for(int a=1;a<=n;a++)cout<<ans[a];
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...