Submission #210676

#TimeUsernameProblemLanguageResultExecution timeMemory
210676peuchDreaming (IOI13_dreaming)C++17
47 / 100
180 ms21880 KiB
#include<bits/stdc++.h> #include "dreaming.h" using namespace std; const int MAXN = 1e5 + 10; int marc[MAXN], dist[MAXN], longDist[2][MAXN]; int aux; vector<int> ar[MAXN]; vector<int> wg[MAXN]; vector<int> group; int dfs1(int cur); int dfs2(int cur); int dfs3(int cur); int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for(int i = 0; i < M; i++){ ar[A[i]].push_back(B[i]); ar[B[i]].push_back(A[i]); wg[A[i]].push_back(T[i]); wg[B[i]].push_back(T[i]); } int ret = 0; for(int i = 0; i < N; i++){ if(marc[i] == 3) continue; dist[i] = 0; aux = 0; int side1 = dfs1(i); longDist[0][side1] = 0; int side2 = dfs2(side1); ret = max(ret, longDist[0][side2]); // printf("group: %d ends = %d and %d with %d nodes\n", group.size(), side1, side2, aux); longDist[1][side2] = 0; group.push_back(dfs3(side2)); } // printf("%d\n", group.size()); // for(int i = 0; i < group.size(); i++) // printf("%d ", group[i]); // printf("\n"); if(group.size() == 1){ for(int i = 0; i < N; i++) ret = max(ret, longDist[0][i]); return ret; } for(int i = 1; i < group.size(); i++){ ret = max(ret, group[i] + group[i - 1] + L); group[i] = min(max(group[i], group[i - 1] + L), max(group[i - 1], group[i] + L)); } return ret; } int dfs1(int cur){ marc[cur] = 1; aux++; int ret = cur; int auxRet = dist[cur]; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; int len = wg[cur][i]; if(marc[viz] == 1) continue; dist[viz] = dist[cur] + len; int dfsVal = dfs1(viz); if(dist[dfsVal] > auxRet) ret = dfsVal, auxRet = dist[dfsVal]; } return ret; } int dfs2(int cur){ marc[cur] = 2; int ret = cur; int auxRet = longDist[0][cur]; for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; int len = wg[cur][i]; if(marc[viz] == 2) continue; longDist[0][viz] = longDist[0][cur] + len; int dfsVal = dfs2(viz); if(longDist[0][dfsVal] > auxRet) ret = dfsVal, auxRet = longDist[0][dfsVal]; } return ret; } int dfs3(int cur){ marc[cur] = 3; int ret = max(longDist[0][cur], longDist[1][cur]); for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; int len = wg[cur][i]; if(marc[viz] == 3) continue; longDist[1][viz] = longDist[1][cur] + len; ret = min(ret, dfs3(viz)); } // printf("%d max(%d %d) -> %d\n", cur, longDist[0][cur], longDist[1][cur], ret); return ret; }

Compilation message (stderr)

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < group.size(); i++){
                 ~~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs1(int)':
dreaming.cpp:59:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs2(int)':
dreaming.cpp:74:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs3(int)':
dreaming.cpp:88:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < ar[cur].size(); i++){
                 ~~^~~~~~~~~~~~~~~~
#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...