Submission #1074207

# Submission time Handle Problem Language Result Execution time Memory
1074207 2024-08-25T08:51:15 Z Trumling Dreaming (IOI13_dreaming) C++14
14 / 100
33 ms 16076 KB
//Dedicated to my love, ivaziva 
#include <bits/stdc++.h> 
#include "dreaming.h"
using namespace std; 
 
using pii = pair<int, int>;
using ll = int64_t;
 
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define dbg(x) cerr << #x << ": " << x << '\n';
 
constexpr int mxN = 1e5 + 20;
vector<pii> g[mxN]; 
int dist1[mxN], dist2[mxN], par[mxN];  
bool vis[mxN];
vector<int> vec, dijametar;
 
void dfs(int x, int p,int &count, int &diamend) {  
    vis[x] = true;   
    vec.push_back(x); 
    par[x] = p;  
    diamend=x;
    for (auto ptr: g[x]) {
        if (ptr.first != p) {  
            count+=ptr.second;
            dist2[ptr.first] = dist2[x] + ptr.second;
          
            dfs(ptr.first, x,count,diamend);  
        }
    }
}  

int travelTime(int N, int M, int L, int* A, int* B, int* T) {
    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]});
    } 
    for (int i = 0; i < N; i++) {
        dist1[i] = 0, dist2[i] = 0;
        vis[i] = false;
    }
    vector<int> diams, anss;
    for (int i = 0; i < N; i++) {
        if (!vis[i] && g[i].size()==1) { 
            dijametar.clear();
            vec.clear(); 
          
            int count=0;
            int diamend = 0;
            dfs(i, -1,count,diamend); 
            int mx = count; 
            
          
            diams.push_back(mx);
            while (diamend != -1) {  
                dijametar.push_back(diamend); 
                diamend = par[diamend];
            }  
            int diff = (int)(2e9), cen = 0, krc = 0;
            for (int x: dijametar) {
                if (diff > abs(dist2[x] - (mx - dist2[x]) )) {
                    diff = abs(dist2[x] - (mx - dist2[x]) );
                    cen = x;
                    krc = dist2[x];
                }
            }
            anss.push_back(max(krc, mx - krc));
        } 
    }     
    int ans = max(diams[0], diams[1]);
    ans = max(ans, anss[0] + anss[1] + L); 
    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:60:36: warning: variable 'cen' set but not used [-Wunused-but-set-variable]
   60 |             int diff = (int)(2e9), cen = 0, krc = 0;
      |                                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 30 ms 16076 KB Output is correct
2 Correct 33 ms 16044 KB Output is correct
3 Correct 19 ms 11480 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 4 ms 3932 KB Output is correct
6 Correct 8 ms 5788 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 16 ms 7260 KB Output is correct
9 Correct 19 ms 9432 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 27 ms 11068 KB Output is correct
12 Correct 31 ms 13484 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 16076 KB Output is correct
2 Correct 33 ms 16044 KB Output is correct
3 Correct 19 ms 11480 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 4 ms 3932 KB Output is correct
6 Correct 8 ms 5788 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 16 ms 7260 KB Output is correct
9 Correct 19 ms 9432 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 27 ms 11068 KB Output is correct
12 Correct 31 ms 13484 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Incorrect 1 ms 2904 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 16076 KB Output is correct
2 Correct 33 ms 16044 KB Output is correct
3 Correct 19 ms 11480 KB Output is correct
4 Correct 6 ms 4956 KB Output is correct
5 Correct 4 ms 3932 KB Output is correct
6 Correct 8 ms 5788 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 16 ms 7260 KB Output is correct
9 Correct 19 ms 9432 KB Output is correct
10 Correct 1 ms 2908 KB Output is correct
11 Correct 27 ms 11068 KB Output is correct
12 Correct 31 ms 13484 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Incorrect 1 ms 2904 KB Output isn't correct
15 Halted 0 ms 0 KB -