답안 #935054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935054 2024-02-28T13:14:04 Z anton 꿈 (IOI13_dreaming) C++17
0 / 100
25 ms 10072 KB
#include "dreaming.h"
#include<bits/stdc++.h>

using namespace std;
#define pii pair<int, int>


struct Tree{
    vector<vector<pii>> adj;
    vector<int> longest;
    int min_len = 1e9;
    int diameter= 0;
};
vector<vector<pii>> madj;
vector<bool> vis;
vector<Tree> forest;


Tree sTree;

void get_tree(int id, int anc){
    //cout<<id<<endl;
    vis[id] = true;
    int tree_id = sTree.adj.size();
    sTree.adj.push_back(vector<pii>(0));
    for(auto e: madj[id]){
        if(e.first!=anc){
            int future_id = sTree.adj.size();
            get_tree(e.first, id);
            sTree.adj[tree_id].push_back(pii(future_id, e.second));
            sTree.adj[future_id].push_back(pii(tree_id, e.second));
        }
    }
    //cout<<id<<" done "<<endl;
}

pii get_len(int id, int anc, Tree& tr){
    vector<int> ch;
    ch.push_back(0);
    ch.push_back(0);

    int max_diam = 0;

    for(auto e: tr.adj[id]){
        if(e.first!=anc){
            pii ch_ans = get_len(e.first, id, tr);
            ch.push_back(ch_ans.first+1);
            max_diam = max(max_diam, ch_ans.second);
        }
    }

    sort(ch.begin(), ch.end());
    return pii(ch[ch.size()-1], max(max_diam, ch[ch.size()-1]+ch[ch.size()-2]));
}

signed travelTime(signed N,signed M, signed L,signed A[], signed B[], signed T[]) {
    madj.resize(N);
    vis.resize(N, false);
    for(int i =0; i<M; i++){
        madj[A[i]-1].push_back(pii(B[i]-1, T[i]));
        madj[B[i]-1].push_back(pii(A[i]-1, T[i]));
    }
    for(int i = 0; i<N; i++){
        
        if(!vis[i]){
            //cerr<<i<<endl;
            sTree.adj.clear();
            get_tree(i, -1);
            forest.push_back(sTree);
        }
    }

    

    
    for(int j = 0; j<forest.size(); j++){
        forest[j].longest.resize(forest[j].adj.size());
    
        for(int i = 0; i<forest[j].adj.size(); i++){
            pii d =  get_len(i, -1, forest[j]);
            //pii d = {100, 100};
            forest[j].longest[i] =d.first;
            forest[j].diameter = d.second;
            forest[j].min_len= min(forest[j].min_len, forest[j].longest[i]);
        }
    }
    if(forest.size()==1){
        return forest[0].diameter;
    }

    return max(forest[0].min_len + forest[1].min_len + L, max(forest[0].diameter, forest[1].diameter));
    return 42;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:76:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Tree>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int j = 0; j<forest.size(); j++){
      |                    ~^~~~~~~~~~~~~~
dreaming.cpp:79:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(int i = 0; i<forest[j].adj.size(); i++){
      |                        ~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 10072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 10072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 9564 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 10072 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -