Submission #1079616

#TimeUsernameProblemLanguageResultExecution timeMemory
1079616mindiyakDreaming (IOI13_dreaming)C++14
22 / 100
1103 ms22248 KiB
#include "dreaming.h" #include <bits/stdc++.h> #include <string> #include <iostream> #include <cmath> #include <numeric> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<int, int> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<ld> vd; typedef vector<long> vl; typedef vector<ull> vull; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<vpi> vvpi; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define nl endl #define S second #define lb lower_bound #define ub upper_bound #define aint(x) x.begin(), x.end() #define raint(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; vi visited; vvpi paths; vi prev_arr; int node = 0; int maxdist = 0; int ans = 0; int n; map<pair<int,int>,int> cons; void dij(int pos){ vi dist(n,-1); prev_arr = vi(n,-1); queue<int> p; p.push(pos); dist[pos] = 0; while(!p.empty()){ int a = p.front();p.pop(); visited[a] = 1; for(auto b:paths[a]){ if(a!= pos && prev_arr[a] == b.F)continue; dist[b.F] = dist[a] + b.S; p.push(b.F); prev_arr[b.F] = a; if(dist[b.F] > maxdist){ maxdist = dist[b.F]; node = b.F; } } } } void dij2(int pos,int prev,int len){ if(len > maxdist){ maxdist = len; node = pos; } cerr << pos << " " << prev << endl; visited[pos] = 1; for(auto a:paths[pos]){ if(a.F == prev)continue; cerr << "s " << a.F << " " << pos << endl; prev_arr[a.F] = pos; dij2(a.F,pos,len+a.S); } } void go_back(int pos,int counter1){ int counter2 = 0; while(prev_arr[pos] != -1){ cerr << pos << " " << prev_arr[pos] << endl; counter1 -= cons[{min(pos,prev_arr[pos]),max(pos,prev_arr[pos])}]; counter2 += cons[{min(pos,prev_arr[pos]),max(pos,prev_arr[pos])}]; maxdist = min(max(counter1,counter2),maxdist); pos = prev_arr[pos]; } } int travelTime(int N, int m, int L, int A[], int B[], int T[]) { if(n==1)return 0; n = N; paths = vvpi(n); visited = vi(n,0); vi distances(n,0); ans = 0; int cnt = 0; FOR(i,0,m){ cons[{min(A[i],B[i]),max(A[i],B[i])}] = T[i]; paths[A[i]].pb({B[i],T[i]}); paths[B[i]].pb({A[i],T[i]}); } for(int i=0;i<n;i++){ if(visited[i])continue; maxdist = 0; node = i; prev_arr = vi(n,-1); dij2(i,-1,0); cerr << "end " << node << " " << maxdist << endl; maxdist = 0; int head = node; node = i; prev_arr = vi(n,-1); dij2(head,-1,0); cerr << "start " << node << " " << maxdist << endl; ans = max(ans,maxdist); go_back(node,maxdist); cerr << "finish " << maxdist << endl << endl; distances[i] = maxdist; cnt += 1; } sort(distances.rbegin(),distances.rend()); if(m == n-1)return ans; if(cnt >= 2)ans = max(ans,distances[0]+distances[1]+L); if(cnt >= 3)ans = max(ans,distances[1]+distances[2]+L+L); return ans; }
#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...