답안 #900261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900261 2024-01-08T02:57:02 Z Faisal_Saqib 악어의 지하 도시 (IOI11_crocodile) C++17
46 / 100
4 ms 8796 KB
#pragma once
#include <vector>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N1=1e5+100;
#define ll long long
vector<pair<int,int>> ma[N1];
ll dp[N1][2];
bool vis[N1],done_for[N1];
void dfs(int x,int p=-1)
{
	if(done_for[x])
	{
		dp[x][0]=dp[x][1]=0;
		return;
	}
	if(vis[x])
		return;
	vis[x]=1;
	vector<ll> pos;
	for(auto [w,y]:ma[x])
	{
		if(!vis[y])
		{
			dfs(y);
			pos.push_back(dp[y][0]+w);
		}
	}
	sort(begin(pos),end(pos));
	for(int j=1;j<pos.size();j++)
	{
		if(dp[x][0]>(pos[j]))
		{
			dp[x][1]=dp[x][0];
			dp[x][0]=pos[j];
		}
		else if((dp[x][1])>(pos[j]))
		{
			dp[x][1]=pos[j];
		}	
	}
}
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[])
{
	for(int i=0;i<n;i++)
		dp[i][0]=dp[i][1]=1e11;
	for(int i=0;i<m;i++)
	{
		ma[r[i][0]].push_back({l[i],r[i][1]});
		ma[r[i][1]].push_back({l[i],r[i][0]});
	}
	for(int i=0;i<k;i++)
		done_for[p[i]]=1;
	dfs(0);
	// cout<<"Hola "<<dp[0][1]<<' '<<dp[0][0]<<endl;
	return dp[0][0];
}

Compilation message

crocodile.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
crocodile.cpp: In function 'void dfs(int, int)':
crocodile.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int j=1;j<pos.size();j++)
      |              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Incorrect 3 ms 8796 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Incorrect 3 ms 8796 KB Output isn't correct
10 Halted 0 ms 0 KB -