Submission #561463

# Submission time Handle Problem Language Result Execution time Memory
561463 2022-05-12T21:29:10 Z Iwanttobreakfree Dreaming (IOI13_dreaming) C++
18 / 100
52 ms 17424 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include "dreaming.h"
using namespace std;
typedef long long ll;
int last_node,max_dist;
void dfs(int a,int par,vector<vector<pair<int,int>>>& g,int& d,vector<bool>& seen,vector<pair<int,int>>& p){
    seen[a]=true;
    for(auto x:g[a]){
        if(x.first==par)continue;
        d+=x.second;
        p[x.first]={a,x.second};
        dfs(x.first,a,g,d,seen,p);
        d-=x.second;
    }
    if(d>max_dist){
        max_dist=d;
        last_node=a;
    }
}
int mid(int a,vector<pair<int,int>>& p){
    vector<int> path;
    int ans=1e9,cnt=0;
    while(a!=-1){
        path.push_back(p[a].second);
        a=p[a].first;
    }
    for(int i=0;i<path.size();i++){
        cnt+=path[i];
        ans=min(ans,max(cnt,max_dist-cnt));
    }
    return ans;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    vector<vector<pair<int,int>>> g(N,vector<pair<int,int>>());
    vector<bool> seen(N,false);
    for(int i=0;i<M;i++){
        g[A[i]].push_back({B[i],T[i]});
        g[B[i]].push_back({A[i],T[i]});
    }
    vector<int> best;
    vector<pair<int,int>>p(N);
    for(int i=0;i<N;i++){
        if(!seen[i]){
            max_dist=-1;
            int di=0;
            dfs(i,i,g,di,seen,p);
            p[last_node].first=-1;
            dfs(last_node,last_node,g,di,seen,p);

            best.push_back(mid(last_node,p));
        }
    }
    sort(best.rbegin(),best.rend());
    int ans=best[0];
    if(best.size()>1)ans=ans+L+best[1];
    for(int i=2;i<best.size();i++){
        ans=max(ans,2*L+best[1]+best[i]);
    }
    //for(int x:best)cout<<x<<' ';
    return ans;
}
/*int main(){
    int n,m,l;
    cin>>n>>m>>l;
    int a[m],b[m],t[m];
    for(int i=0;i<m;i++)cin>>a[i]>>b[i]>>t[i];
    cout<<travelTime(n,m,l,a,b,t);
}*/

Compilation message

dreaming.cpp: In function 'int mid(int, std::vector<std::pair<int, int> >&)':
dreaming.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<path.size();i++){
      |                 ~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=2;i<best.size();i++){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 17424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 17424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6324 KB Output is correct
2 Correct 21 ms 6312 KB Output is correct
3 Correct 21 ms 6284 KB Output is correct
4 Correct 21 ms 6372 KB Output is correct
5 Correct 24 ms 6296 KB Output is correct
6 Correct 42 ms 6956 KB Output is correct
7 Correct 27 ms 6548 KB Output is correct
8 Correct 36 ms 6260 KB Output is correct
9 Correct 25 ms 6232 KB Output is correct
10 Correct 21 ms 6500 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 4048 KB Output is correct
13 Correct 8 ms 4148 KB Output is correct
14 Correct 7 ms 4048 KB Output is correct
15 Correct 7 ms 4048 KB Output is correct
16 Correct 8 ms 4048 KB Output is correct
17 Correct 9 ms 4048 KB Output is correct
18 Correct 7 ms 4176 KB Output is correct
19 Correct 7 ms 4048 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 7 ms 4048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 17424 KB Output isn't correct
2 Halted 0 ms 0 KB -