답안 #1083187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083187 2024-09-02T17:32:42 Z rayan_bd 악어의 지하 도시 (IOI11_crocodile) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; 


#define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())

const int mxN = 5000;
const ll INF = 1e18;

vector<pair<ll,ll>> adj[mxN];
vector<bool> exitt(mxN,0),cantgo(mxN,0);
ll dist[mxN];

void dfs(ll u=0,ll par=-1){
	if(exitt[u]) return;
	pair<ll,ll> p={-1,INF};// node with min dist
	for(auto it:adj[u]){
		if(it.first!=par){
			dfs(it.first,u);
			if(p.second>it.second+dist[it.first]){
				p.second=it.second+dist[it.first];
				p.first=it.first;
			}
		}
	}
	cantgo[p.first]=1;
	dist[u]=p.second;
}


ll solN(ll u=0,ll par=-1){
	if(exitt[u]) return 0;
	ll ans=INF;
	for(auto it:adj[u]){
		if(it.first!=par&&!cantgo[it.first]){
			ans=min(ans,it.second+solN(it.first,u));
		}
	}
	return ans;
}

ll travel_plan(int n,int m,int r[][2],int l[],int k,int p[]){
	
	for(int i=0;i<m;++i){
		ll u=r[i][0],v=r[i][1],w=l[i];
		adj[u].pb({v,w});
		adj[v].pb({u,w});
	}

	for(int i=0;i<k;++i) exitt[p[i]]=1;

	if(k==1){
		return solN();
	}

	dfs();
	return solN();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -