Submission #1023826

#TimeUsernameProblemLanguageResultExecution timeMemory
1023826dozerDreaming (IOI13_dreaming)C++14
40 / 100
1054 ms18588 KiB
#include <bits/stdc++.h> using namespace std; #include "dreaming.h" #define sp " " #define endl "\n" #define pb push_back #define pii pair<int, int> #define st first #define nd second #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define mid (l + r) / 2 #define LL node * 2 #define RR node * 2 + 1 #define ll long long #define MAXN 300005 const int modulo = 1e9 + 7; const ll INF = 2e18 + 7; #define fail(s, x...) do { \ fprintf(stderr, s "\n", ## x); \ exit(1); \ } while(0) #define MAX_N 100000 int maks[MAXN], sub_maks[MAXN], maks3[MAXN], vis[MAXN]; vector<pii> adj[MAXN]; int MINI; void dfs2(int node, int root){ int ans = 0; for (auto i : adj[node]){ if (i.st == root) continue; dfs2(i.st, node); ans = max(ans, sub_maks[i.st] + i.nd); } sub_maks[node] = ans; } void dfs3(int node, int root){ dfs2(node, 0); vis[node] = 1; maks3[node] = sub_maks[node]; MINI = min(MINI, maks3[node]); for (auto i : adj[node]){ if (i.st == root) continue; dfs3(i.st, node); } } void dfs(int node, int root, int m){ vis[node] = 1; maks[node] = max(m, sub_maks[node]); MINI = min(MINI, maks[node]); vector<array<int, 3>> v; for (auto i : adj[node]){ if (i.st == root) continue; v.pb({sub_maks[i.st] + i.nd, i.st, i.nd}); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++){ int to = v[i][1], w = v[i][2]; int add = m; if (i + 1 < v.size()) add = max(add, v.back()[0]); else add = max(add, v[v.size() - 2][0]); dfs(to, node, add + w); } } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for (int i = 1; i <= N; i++){ vis[i] = 0, adj[i].clear(), maks[i] = 0, sub_maks[i] = 0, maks3[i] = 0; } for (int i = 0; i < M; i++){ A[i]++, B[i]++; adj[A[i]].pb({B[i], T[i]}); adj[B[i]].pb({A[i], T[i]}); } int ANS = 0; priority_queue<int> q; for (int i = 1; i <= N; i++){ if (vis[i]) continue; MINI = modulo; /* dfs2(i, 0); dfs(i, 0, 0);*/ dfs3(i, 0); q.push(MINI); } for (int i = 1; i <= N; i++) ANS = max(ANS, maks3[i]); while(!q.empty()){ int a = q.top(); q.pop(); if (q.empty()) break; int b = q.top(); q.pop(); int neww = max(a, b + L); ANS = max(ANS, a + b + L); q.push(neww); } return ANS; } /* static int A[MAX_N]; static int B[MAX_N]; static int T[MAX_N]; int main() { int N, M, L, i; int res; fileio(); FILE *f = fopen("input.txt", "r"); if (!f) fail("Failed to open input file."); res = fscanf(f, "%d%d%d", &N, &M, &L); for (i = 0; i < M; i++) res = fscanf(f, "%d%d%d", &A[i], &B[i], &T[i]); fclose(f); int answer = travelTime(N, M, L, A, B, T); printf("%d\n", answer); return 0; } */

Compilation message (stderr)

dreaming.cpp: In function 'void dfs(int, int, int)':
dreaming.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for (int i = 0; i < v.size(); i++){
      |                  ~~^~~~~~~~~~
dreaming.cpp:73:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   if (i + 1 < v.size()) add = max(add, v.back()[0]);
      |       ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...