답안 #900868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900868 2024-01-09T04:44:00 Z gun_gan 꿈 (IOI13_dreaming) C++17
0 / 100
36 ms 28548 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 3e5 + 5;
int N, M, L;
vector<pair<int,int>> g[MX], h[MX];

bool vis[MX];

int cur = 0, mx = 0, z = 0;

vector<int> vec;
pair<int,int> par[MX];

void dfs(int v) {
      vis[v] = 1;
      vec.push_back(v);
      if(cur > mx) {
            mx = cur;
            z = v;
      }
      for(auto [u, w] : g[v]) {
            if(!vis[u]) {
                  cur += w;
                  par[u] = {v, w};
                  dfs(u);
                  cur -= w;
            }
      }
}

vector<pair<int,int>> P;

void dfs2(int v) {
      vis[v] = 1;
      if(cur > mx) {
            mx = cur;
            z = v;
      }
      for(auto [u, w] : h[v]) {
            if(!vis[u]) {
                  cur += w;
                  dfs2(u);
                  cur -= w;
            }
      }
}

int calc() {
      int n = 1;
      for(auto [x, y] : P) {
            h[n].push_back({n + 1, x});
            h[n + 1].push_back({n, x});
            h[n + 1].push_back({n + 2, y});
            h[n + 2].push_back({n + 1, y});
            if(n > 1) {
                  h[2].push_back({n + 1, L});
                  h[n + 1].push_back({2, L});
            }
            n += 3;
      }
      cur = 0, mx = 0, z = 0;
      for(int i = 1; i < n; i++) vis[i] = 0; 
      dfs2(1);
      cur = 0, mx = 0;
      for(int i = 1; i < n; i++) vis[i] = 0; 
      dfs2(z);
      return mx;
}

int travelTime(int _N, int _M, int _L, int A[], int B[], int T[]) {
      N = _N, M = _M, L = _L;
      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 = 1; i <= N; i++) {
            if(vis[i]) continue;
            vec.clear();
            cur = 0, mx = 0, z = 0;

            dfs(i);
            for(auto x : vec) {
                  vis[x] = 0;
                  par[x] = {z, 0};
            }

            if(vec.size() == 1) {
                  for(auto x : vec) {
                        vis[x] = 1;
                  }
                  P.push_back({0, 0});
                  continue;
            }

            vec.clear();
            int tz = z;
            cur = 0, mx = 0, z = 0;
            par[tz] = {tz, 0};
            dfs(tz);

            int k = z, sum = 0, y = 2e9, p = 0, q = 0, len = mx;
            while(k != tz) {
                  if(abs((sum) - (len - sum)) < y) {
                        y = abs((sum) - (len - sum));
                        p = sum;
                        q = len - sum;
                  }
                  sum += par[k].second;
                  k = par[k].first;
            }

            vec.clear();

            P.push_back({max(p, q), min(p, q)});
      }

      return calc();
}

/*
int aa[100], bb[100], cc[100];

int main() {
      aa[0] = 1, bb[0] = 2, cc[0] = 1;
      aa[1] = 2, bb[1] = 3, cc[1] = 3;
      aa[2] = 3, bb[2] = 4, cc[2] = 7;
      aa[3] = 4, bb[3] = 5, cc[3] = 14;
      aa[4] = 6, bb[4] = 7, cc[4] = 3;
      aa[5] = 7, bb[5] = 8, cc[5] = 7; 
      aa[6] = 8, bb[6] = 9, cc[6] = 7; 
      aa[7] = 9, bb[7] = 10, cc[7] = 7;

      cout << travelTime(10, 8, 1, aa, bb, cc) << '\n';
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 28548 KB Output is correct
2 Correct 36 ms 28396 KB Output is correct
3 Correct 24 ms 25156 KB Output is correct
4 Correct 9 ms 19548 KB Output is correct
5 Correct 7 ms 18780 KB Output is correct
6 Correct 11 ms 20584 KB Output is correct
7 Incorrect 5 ms 18008 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 5 ms 18008 KB Output is correct
3 Incorrect 4 ms 18012 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 28548 KB Output is correct
2 Correct 36 ms 28396 KB Output is correct
3 Correct 24 ms 25156 KB Output is correct
4 Correct 9 ms 19548 KB Output is correct
5 Correct 7 ms 18780 KB Output is correct
6 Correct 11 ms 20584 KB Output is correct
7 Incorrect 5 ms 18008 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 28472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 18012 KB Output is correct
2 Correct 5 ms 18008 KB Output is correct
3 Incorrect 4 ms 18012 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 28548 KB Output is correct
2 Correct 36 ms 28396 KB Output is correct
3 Correct 24 ms 25156 KB Output is correct
4 Correct 9 ms 19548 KB Output is correct
5 Correct 7 ms 18780 KB Output is correct
6 Correct 11 ms 20584 KB Output is correct
7 Incorrect 5 ms 18008 KB Output isn't correct
8 Halted 0 ms 0 KB -