# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
536259 | 2022-03-12T16:44:31 Z | groshi | Dreaming (IOI13_dreaming) | C++17 | 53 ms | 13972 KB |
#include<iostream> #include<vector> #include<algorithm> #include "dreaming.h" using namespace std; bool odw[110000]; struct wi{ vector<int> Q; int maxx1=0,maxx2=0,skad1=0,skad2=0; int maxx=0; int ojc=0; int czym=0; int odw2=0; int odw3=0; }*w; int dfs(int x) { odw[x]=1; int wynik=0; for(int i=0;i<w[x].Q.size();i+=2) { int pom=w[x].Q[i]; if(odw[pom]==1) continue; w[pom].ojc=x; w[pom].czym=w[x].Q[i+1]; int ile=dfs(pom); if(ile+w[x].Q[i+1]>w[x].maxx1) { w[x].maxx2=w[x].maxx1; w[x].skad2=w[x].skad1; w[x].maxx1=ile+w[x].Q[i+1]; w[x].skad1=pom; } else if(ile+w[x].Q[i+1]>w[x].maxx2) { w[x].maxx2=ile+w[x].Q[i+1]; w[x].skad2=pom; } wynik=max(wynik,ile+w[x].Q[i+1]); } return wynik; } void dfs2(int x) { w[x].odw2=1; for(int i=0;i<w[x].Q.size();i+=2) { int pom=w[x].Q[i]; if(w[pom].odw2==1) continue; if(w[x].skad1==pom && w[x].maxx2+w[x].Q[i+1]>w[pom].maxx1) { w[pom].maxx2=w[pom].maxx1; w[pom].skad2=w[pom].skad1; w[pom].maxx1=w[x].maxx2+w[x].Q[i+1]; w[pom].skad1=x; } else if(w[x].skad1==pom && w[x].maxx2+w[x].Q[i+1]>w[pom].maxx2) { w[pom].maxx2=w[x].maxx2+w[x].Q[i+1]; w[pom].skad2=x; } else if(w[x].skad1!=pom && w[x].maxx1+w[x].Q[i+1]>w[pom].maxx1) { w[pom].maxx2=w[pom].maxx1; w[pom].skad2=w[pom].skad1; w[pom].maxx1=w[x].maxx1+w[x].Q[i+1]; w[pom].skad1=x; } else if(w[x].skad1!=pom && w[x].maxx2+w[x].Q[i+1]>w[pom].maxx2) { w[pom].maxx2=w[x].maxx2+w[x].Q[i+1]; w[pom].skad2=x; } dfs2(pom); } } int dfs3(int x) { w[x].odw3=1; int wypisz=0; wypisz=w[x].maxx1; for(int i=0;i<w[x].Q.size();i+=2) { int pom=w[x].Q[i]; if(w[pom].odw3==1) continue; int cos=dfs3(pom); wypisz=min(wypisz,cos); } return wypisz; } int travelTime(int n,int m,int l,int A[],int B[],int T[]) { w=new wi[n+3]; for(int i=0;i<m;i++) { w[A[i]].Q.push_back(B[i]); w[A[i]].Q.push_back(T[i]); w[B[i]].Q.push_back(A[i]); w[B[i]].Q.push_back(T[i]); } for(int i=0;i<n;i++) { if(odw[i]==1) continue; int maxx=dfs(i); } for(int i=0;i<n;i++) { if(w[i].odw2==1) continue; dfs2(i); } vector<int> drogi; for(int i=0;i<n;i++) { if(w[i].odw3==1) continue; int ile=dfs3(i); drogi.push_back(ile); } sort(drogi.begin(),drogi.end()); int wypisz=drogi.back(); if(drogi.size()>1) wypisz=max(wypisz,drogi[drogi.size()-2]+drogi.back()+l); if(drogi.size()>2) wypisz=max(wypisz,drogi[drogi.size()-2]+drogi[drogi.size()-3]+2*l); return wypisz; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 53 ms | 13972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 53 ms | 13972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 8984 KB | Output is correct |
2 | Correct | 30 ms | 8968 KB | Output is correct |
3 | Correct | 36 ms | 9348 KB | Output is correct |
4 | Correct | 29 ms | 9368 KB | Output is correct |
5 | Correct | 25 ms | 9280 KB | Output is correct |
6 | Correct | 40 ms | 10164 KB | Output is correct |
7 | Correct | 29 ms | 9696 KB | Output is correct |
8 | Correct | 27 ms | 9168 KB | Output is correct |
9 | Correct | 28 ms | 9096 KB | Output is correct |
10 | Correct | 27 ms | 9676 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 7248 KB | Output is correct |
13 | Correct | 6 ms | 7376 KB | Output is correct |
14 | Correct | 7 ms | 7248 KB | Output is correct |
15 | Correct | 6 ms | 7248 KB | Output is correct |
16 | Correct | 6 ms | 7248 KB | Output is correct |
17 | Correct | 6 ms | 7248 KB | Output is correct |
18 | Correct | 7 ms | 7376 KB | Output is correct |
19 | Correct | 6 ms | 7248 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 468 KB | Output is correct |
23 | Correct | 6 ms | 7248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 53 ms | 13972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |