Submission #1074156

# Submission time Handle Problem Language Result Execution time Memory
1074156 2024-08-25T08:27:17 Z Trumling Dreaming (IOI13_dreaming) C++14
0 / 100
56 ms 15056 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
#define INF 99999999999999999
#define MOD 1000000007
#define all(x) x.begin(),x.end()

vector<vector<pair<ll,ll>>>g;
vector<bool>vis;
ll n,m;
void dfs1(int start,ll &count)
{
    for(auto x:g[start])
        if(!vis[x.F])
        {
            vis[x.F]=1;
            count+=x.S;
            dfs1(x.F, count);
        }
}

void dfs2(int start,int pre,ll &ans,ll diff,ll curr,ll count)
{
    if(diff > abs((count-curr)-curr))
            {
                ans=max(curr,count-curr);
                diff= abs((count-curr)-curr);
            }

    for(auto x:g[start])
        if(x.F!=pre)
            dfs2(x.F,start,ans,diff,curr + x.S,count);
        
}   
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N;
    m=M;

    g.assign(n,vector<pair<ll,ll>>());
    vis.assign(n,0);

    for(int i=0;i<m;i++)
        {
            g[A[i]].pb({B[i],T[i]});
            g[B[i]].pb({A[i],T[i]});
        }
    
    vector<ll>ans(3,0);
    ll idx=0;
    for(int i=0;i<N;i++)
        if(!vis[i] && g[i].size()==1)
        {
            vis[i]=1;
            ll count=0;
            dfs1(i,count);
            ans[2]=max(ans[2],count);

            dfs2(i,i,ans[idx++],count,0,count);

        }
    


    return max(ans[2],ans[0] + ans[1] + L);

}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 15056 KB Output is correct
2 Correct 56 ms 15012 KB Output is correct
3 Correct 41 ms 9808 KB Output is correct
4 Correct 9 ms 2396 KB Output is correct
5 Correct 7 ms 1628 KB Output is correct
6 Correct 13 ms 3668 KB Output is correct
7 Incorrect 1 ms 508 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 15056 KB Output is correct
2 Correct 56 ms 15012 KB Output is correct
3 Correct 41 ms 9808 KB Output is correct
4 Correct 9 ms 2396 KB Output is correct
5 Correct 7 ms 1628 KB Output is correct
6 Correct 13 ms 3668 KB Output is correct
7 Incorrect 1 ms 508 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 4988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 15056 KB Output is correct
2 Correct 56 ms 15012 KB Output is correct
3 Correct 41 ms 9808 KB Output is correct
4 Correct 9 ms 2396 KB Output is correct
5 Correct 7 ms 1628 KB Output is correct
6 Correct 13 ms 3668 KB Output is correct
7 Incorrect 1 ms 508 KB Output isn't correct
8 Halted 0 ms 0 KB -