| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1317213 | huseynahmadli2010 | 꿈 (IOI13_dreaming) | C++20 | 0 ms | 0 KiB |
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int sz=1e6+5;
vector<pair<int,int>> graph[sz];
bool visited[sz];
int sum=0;
void dfs(int v)
{
visited[v]=true;
for(auto &[to,w] : graph[v])
{
if(!visited[to])
{
dfs(to);
sum+=w;
}
}
}
int travelTime(int n,int m,int l,int a[],int b[],int t[])
{
for(int i=0;i<m;i++)
{
graph[a[i]].push_back({b[i],t[i]});
graph[b[i]].push_back({a[i],t[i]});
}
vector<int> res;
for(int i=0;i<n;i++)
{
if(!visited[i])
{
dfs(i);
res.push_back(sum);
sum=0;
}
}
if(res.size()==1)
return res[0];
sort(res.rbegin(),res.rend());
return (res[0]+res[1]+l);
}
