Submission #858716

# Submission time Handle Problem Language Result Execution time Memory
858716 2023-10-09T05:21:07 Z damwuan Dreaming (IOI13_dreaming) C++17
47 / 100
53 ms 22836 KB
#include "dreaming.h"
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=(j);i<=(k);i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
//#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<int> vi;
const ll maxn=2e5+5;
const ll offset=1e18;
const ll block_sz=317;
const ll inf=1e18;
const ll mod=1e9+7;
 
vector<int> adj[maxn];
bool vis[maxn];
int a[maxn],b[maxn],t[maxn],dep[maxn],g;
int dfs(int u,int pre)
{
    int x=u,y;
    vis[u]=true;
    for(int i: adj[u])
    {
        int v=u^a[i]^b[i];
        int w=t[i];
        if (v==pre) continue;
        dep[v]=dep[u]+w;
        y=dfs(v,u);
        if (dep[y]>dep[x]) x=y;
    }
    return x;
}
vector<int> L;
bool ok=0;
void dfs1(int u,int pre,int aim)
{
    L.pb(u);
    if (u==aim) ok=1;
    if (ok) return;
    for(int i: adj[u])
    {
        int v=u^a[i]^b[i];
        int w=t[i];
        if (v==pre) continue;
        dfs1(v,u,aim);
        if (ok) return;
    }
    L.pop_back();
}
int Find_diameter(int u)
{
    dep[u]=0;
    u=dfs(u,u);
    dep[u]=0;
    int v=dfs(u,u);
    g=max(g,dep[v]);
//    cerr<< "wtf "<<v<<'\n';
    ok=0;
    L.clear();
    dfs1(u,u,v);
//    for(int kz:L) cerr<< "ad "<<kz<<' '<<dep[kz]<<' '<<dep[v]-dep[kz]<<'\n';
    if (L.size()==1) return 0;
    for1(i,0,L.size()-2)
    {
//        cerr<<  "clmm "<<L[i]<<'\n';
        int x1=max(dep[L[i]],dep[v]-dep[L[i]]);
        int x2=max(dep[L[i+1]],dep[v]-dep[L[i+1]]);
        if (x2>=x1) return x1;
    }
}
vector<int> Lis;
int travelTime(int n, int m, int l, int A[], int B[], int T[])
{
    for1(i,1,m)
    {
        a[i]=A[i-1]+1;
        b[i]=B[i-1]+1;
        t[i]=T[i-1];
    }
    for1(i,1,m)
    {
        adj[a[i]].pb(i);
        adj[b[i]].pb(i);
//        cerr<< a[i]<<' '<<b[i]<<' '<<t[i]<<'\n';
    }
//    return 2;
    for1(i,1,n)
    {
 
        if (!vis[i])
        {
            int x=Find_diameter(i);
//            cerr<< i<<' '<<x<<'\n';
            Lis.pb(x);
        }
    }
//    for(int v:Lis) cerr<< v<<'\n';
    sort(all(Lis),greater<int>());
    if (Lis.size()==1)
    {
        return max(g,Lis[0]);
    }
    else
    {
        return max(g,Lis[0]+Lis[1]+l);
    }
//return 42;
}
//
//#define fail(s, x...) do { \
//		fprintf(stderr, s "\n", ## x); \
//		exit(1); \
//	} while(0)
//
//#define MAX_N 100000
//
//static int A[MAX_N];
//static int B[MAX_N];
//static int T[MAX_N];
//
//int main() {
//	int N, M, L, i;
//	int res;
//
//	FILE *f = fopen("dreaming.in", "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

dreaming.cpp:125:1: warning: multi-line comment [-Wcomment]
  125 | //#define fail(s, x...) do { \
      | ^
dreaming.cpp: In function 'void dfs1(int, int, int)':
dreaming.cpp:58:13: warning: unused variable 'w' [-Wunused-variable]
   58 |         int w=t[i];
      |             ^
dreaming.cpp: In function 'int Find_diameter(int)':
dreaming.cpp:9:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define for1(i,j,k) for(int i=(j);i<=(k);i++)
      |                                    ^
dreaming.cpp:78:5: note: in expansion of macro 'for1'
   78 |     for1(i,0,L.size()-2)
      |     ^~~~
dreaming.cpp:85:1: warning: control reaches end of non-void function [-Wreturn-type]
   85 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 36 ms 20184 KB Output is correct
2 Correct 36 ms 21208 KB Output is correct
3 Correct 24 ms 17492 KB Output is correct
4 Correct 7 ms 11100 KB Output is correct
5 Correct 5 ms 10332 KB Output is correct
6 Correct 11 ms 12124 KB Output is correct
7 Correct 2 ms 9356 KB Output is correct
8 Correct 19 ms 13404 KB Output is correct
9 Correct 24 ms 15188 KB Output is correct
10 Correct 2 ms 9308 KB Output is correct
11 Correct 34 ms 16988 KB Output is correct
12 Correct 37 ms 19212 KB Output is correct
13 Correct 2 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9308 KB Output is correct
3 Correct 2 ms 9304 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9308 KB Output is correct
6 Correct 2 ms 9308 KB Output is correct
7 Correct 2 ms 9240 KB Output is correct
8 Correct 2 ms 9304 KB Output is correct
9 Correct 2 ms 9308 KB Output is correct
10 Correct 2 ms 9308 KB Output is correct
11 Correct 2 ms 9304 KB Output is correct
12 Correct 2 ms 9308 KB Output is correct
13 Correct 2 ms 9452 KB Output is correct
14 Correct 2 ms 9392 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 9308 KB Output is correct
17 Correct 2 ms 9308 KB Output is correct
18 Correct 2 ms 9308 KB Output is correct
19 Correct 2 ms 9308 KB Output is correct
20 Correct 2 ms 9308 KB Output is correct
21 Correct 2 ms 9308 KB Output is correct
22 Correct 2 ms 9308 KB Output is correct
23 Correct 2 ms 9452 KB Output is correct
24 Correct 2 ms 9308 KB Output is correct
25 Correct 2 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 20184 KB Output is correct
2 Correct 36 ms 21208 KB Output is correct
3 Correct 24 ms 17492 KB Output is correct
4 Correct 7 ms 11100 KB Output is correct
5 Correct 5 ms 10332 KB Output is correct
6 Correct 11 ms 12124 KB Output is correct
7 Correct 2 ms 9356 KB Output is correct
8 Correct 19 ms 13404 KB Output is correct
9 Correct 24 ms 15188 KB Output is correct
10 Correct 2 ms 9308 KB Output is correct
11 Correct 34 ms 16988 KB Output is correct
12 Correct 37 ms 19212 KB Output is correct
13 Correct 2 ms 9304 KB Output is correct
14 Correct 2 ms 9304 KB Output is correct
15 Correct 2 ms 9308 KB Output is correct
16 Correct 2 ms 9304 KB Output is correct
17 Correct 2 ms 9304 KB Output is correct
18 Correct 2 ms 9308 KB Output is correct
19 Correct 2 ms 9308 KB Output is correct
20 Correct 2 ms 9240 KB Output is correct
21 Correct 2 ms 9304 KB Output is correct
22 Correct 2 ms 9308 KB Output is correct
23 Correct 2 ms 9308 KB Output is correct
24 Correct 2 ms 9304 KB Output is correct
25 Correct 2 ms 9308 KB Output is correct
26 Correct 2 ms 9452 KB Output is correct
27 Correct 2 ms 9392 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 2 ms 9308 KB Output is correct
30 Correct 2 ms 9308 KB Output is correct
31 Correct 2 ms 9308 KB Output is correct
32 Correct 2 ms 9308 KB Output is correct
33 Correct 2 ms 9308 KB Output is correct
34 Correct 2 ms 9308 KB Output is correct
35 Correct 2 ms 9308 KB Output is correct
36 Correct 2 ms 9452 KB Output is correct
37 Correct 2 ms 9308 KB Output is correct
38 Correct 2 ms 9308 KB Output is correct
39 Correct 35 ms 21468 KB Output is correct
40 Correct 36 ms 21468 KB Output is correct
41 Correct 29 ms 17392 KB Output is correct
42 Correct 6 ms 11100 KB Output is correct
43 Correct 2 ms 9396 KB Output is correct
44 Correct 2 ms 9308 KB Output is correct
45 Correct 2 ms 9308 KB Output is correct
46 Correct 2 ms 9308 KB Output is correct
47 Correct 2 ms 9304 KB Output is correct
48 Correct 2 ms 9308 KB Output is correct
49 Correct 2 ms 9308 KB Output is correct
50 Correct 2 ms 9308 KB Output is correct
51 Correct 2 ms 9308 KB Output is correct
52 Correct 2 ms 9452 KB Output is correct
53 Correct 2 ms 9448 KB Output is correct
54 Correct 2 ms 9308 KB Output is correct
55 Correct 2 ms 9304 KB Output is correct
56 Correct 2 ms 9308 KB Output is correct
57 Correct 40 ms 14084 KB Output is correct
58 Correct 40 ms 13908 KB Output is correct
59 Correct 38 ms 14244 KB Output is correct
60 Correct 39 ms 14164 KB Output is correct
61 Correct 49 ms 14208 KB Output is correct
62 Correct 40 ms 14416 KB Output is correct
63 Correct 42 ms 14164 KB Output is correct
64 Correct 35 ms 14160 KB Output is correct
65 Correct 36 ms 14420 KB Output is correct
66 Correct 38 ms 14212 KB Output is correct
67 Correct 40 ms 14168 KB Output is correct
68 Correct 39 ms 14120 KB Output is correct
69 Correct 40 ms 14416 KB Output is correct
70 Correct 41 ms 14416 KB Output is correct
71 Correct 2 ms 7260 KB Output is correct
72 Correct 3 ms 9564 KB Output is correct
73 Correct 3 ms 9484 KB Output is correct
74 Correct 3 ms 9564 KB Output is correct
75 Correct 3 ms 9564 KB Output is correct
76 Correct 2 ms 9564 KB Output is correct
77 Correct 3 ms 9496 KB Output is correct
78 Correct 3 ms 9564 KB Output is correct
79 Correct 3 ms 9564 KB Output is correct
80 Correct 40 ms 14096 KB Output is correct
81 Correct 40 ms 14172 KB Output is correct
82 Correct 39 ms 14420 KB Output is correct
83 Correct 39 ms 14428 KB Output is correct
84 Correct 2 ms 9564 KB Output is correct
85 Correct 2 ms 9564 KB Output is correct
86 Correct 2 ms 9464 KB Output is correct
87 Correct 3 ms 9496 KB Output is correct
88 Correct 3 ms 9584 KB Output is correct
89 Correct 2 ms 9564 KB Output is correct
90 Correct 4 ms 9564 KB Output is correct
91 Correct 4 ms 9564 KB Output is correct
92 Correct 3 ms 9564 KB Output is correct
93 Correct 2 ms 9564 KB Output is correct
94 Correct 2 ms 9452 KB Output is correct
95 Correct 3 ms 9704 KB Output is correct
96 Correct 2 ms 9308 KB Output is correct
97 Correct 2 ms 9308 KB Output is correct
98 Correct 2 ms 9308 KB Output is correct
99 Correct 2 ms 9308 KB Output is correct
100 Correct 2 ms 9308 KB Output is correct
101 Correct 2 ms 9448 KB Output is correct
102 Correct 2 ms 9308 KB Output is correct
103 Correct 2 ms 9464 KB Output is correct
104 Correct 5 ms 10332 KB Output is correct
105 Correct 11 ms 12224 KB Output is correct
106 Correct 2 ms 9308 KB Output is correct
107 Correct 21 ms 13340 KB Output is correct
108 Correct 27 ms 15324 KB Output is correct
109 Correct 2 ms 9564 KB Output is correct
110 Correct 34 ms 16924 KB Output is correct
111 Correct 38 ms 19172 KB Output is correct
112 Correct 2 ms 9308 KB Output is correct
113 Correct 53 ms 22836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 11864 KB Output is correct
2 Incorrect 14 ms 11864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9304 KB Output is correct
2 Correct 2 ms 9308 KB Output is correct
3 Correct 2 ms 9304 KB Output is correct
4 Correct 2 ms 9304 KB Output is correct
5 Correct 2 ms 9308 KB Output is correct
6 Correct 2 ms 9308 KB Output is correct
7 Correct 2 ms 9240 KB Output is correct
8 Correct 2 ms 9304 KB Output is correct
9 Correct 2 ms 9308 KB Output is correct
10 Correct 2 ms 9308 KB Output is correct
11 Correct 2 ms 9304 KB Output is correct
12 Correct 2 ms 9308 KB Output is correct
13 Correct 2 ms 9452 KB Output is correct
14 Correct 2 ms 9392 KB Output is correct
15 Correct 2 ms 7260 KB Output is correct
16 Correct 2 ms 9308 KB Output is correct
17 Correct 2 ms 9308 KB Output is correct
18 Correct 2 ms 9308 KB Output is correct
19 Correct 2 ms 9308 KB Output is correct
20 Correct 2 ms 9308 KB Output is correct
21 Correct 2 ms 9308 KB Output is correct
22 Correct 2 ms 9308 KB Output is correct
23 Correct 2 ms 9452 KB Output is correct
24 Correct 2 ms 9308 KB Output is correct
25 Correct 2 ms 9308 KB Output is correct
26 Correct 2 ms 9308 KB Output is correct
27 Correct 2 ms 9308 KB Output is correct
28 Correct 3 ms 9564 KB Output is correct
29 Correct 2 ms 9352 KB Output is correct
30 Correct 2 ms 9308 KB Output is correct
31 Correct 2 ms 9564 KB Output is correct
32 Incorrect 2 ms 9308 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 20184 KB Output is correct
2 Correct 36 ms 21208 KB Output is correct
3 Correct 24 ms 17492 KB Output is correct
4 Correct 7 ms 11100 KB Output is correct
5 Correct 5 ms 10332 KB Output is correct
6 Correct 11 ms 12124 KB Output is correct
7 Correct 2 ms 9356 KB Output is correct
8 Correct 19 ms 13404 KB Output is correct
9 Correct 24 ms 15188 KB Output is correct
10 Correct 2 ms 9308 KB Output is correct
11 Correct 34 ms 16988 KB Output is correct
12 Correct 37 ms 19212 KB Output is correct
13 Correct 2 ms 9304 KB Output is correct
14 Correct 2 ms 9304 KB Output is correct
15 Correct 2 ms 9308 KB Output is correct
16 Correct 2 ms 9304 KB Output is correct
17 Correct 2 ms 9304 KB Output is correct
18 Correct 2 ms 9308 KB Output is correct
19 Correct 2 ms 9308 KB Output is correct
20 Correct 2 ms 9240 KB Output is correct
21 Correct 2 ms 9304 KB Output is correct
22 Correct 2 ms 9308 KB Output is correct
23 Correct 2 ms 9308 KB Output is correct
24 Correct 2 ms 9304 KB Output is correct
25 Correct 2 ms 9308 KB Output is correct
26 Correct 2 ms 9452 KB Output is correct
27 Correct 2 ms 9392 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 2 ms 9308 KB Output is correct
30 Correct 2 ms 9308 KB Output is correct
31 Correct 2 ms 9308 KB Output is correct
32 Correct 2 ms 9308 KB Output is correct
33 Correct 2 ms 9308 KB Output is correct
34 Correct 2 ms 9308 KB Output is correct
35 Correct 2 ms 9308 KB Output is correct
36 Correct 2 ms 9452 KB Output is correct
37 Correct 2 ms 9308 KB Output is correct
38 Correct 2 ms 9308 KB Output is correct
39 Correct 35 ms 21468 KB Output is correct
40 Correct 36 ms 21468 KB Output is correct
41 Correct 29 ms 17392 KB Output is correct
42 Correct 6 ms 11100 KB Output is correct
43 Correct 2 ms 9396 KB Output is correct
44 Correct 2 ms 9308 KB Output is correct
45 Correct 2 ms 9308 KB Output is correct
46 Correct 2 ms 9308 KB Output is correct
47 Correct 2 ms 9304 KB Output is correct
48 Correct 2 ms 9308 KB Output is correct
49 Correct 2 ms 9308 KB Output is correct
50 Correct 2 ms 9308 KB Output is correct
51 Correct 2 ms 9308 KB Output is correct
52 Correct 2 ms 9452 KB Output is correct
53 Correct 2 ms 9448 KB Output is correct
54 Correct 2 ms 9308 KB Output is correct
55 Correct 2 ms 9304 KB Output is correct
56 Correct 2 ms 9308 KB Output is correct
57 Correct 40 ms 14084 KB Output is correct
58 Correct 40 ms 13908 KB Output is correct
59 Correct 38 ms 14244 KB Output is correct
60 Correct 39 ms 14164 KB Output is correct
61 Correct 49 ms 14208 KB Output is correct
62 Correct 40 ms 14416 KB Output is correct
63 Correct 42 ms 14164 KB Output is correct
64 Correct 35 ms 14160 KB Output is correct
65 Correct 36 ms 14420 KB Output is correct
66 Correct 38 ms 14212 KB Output is correct
67 Correct 40 ms 14168 KB Output is correct
68 Correct 39 ms 14120 KB Output is correct
69 Correct 40 ms 14416 KB Output is correct
70 Correct 41 ms 14416 KB Output is correct
71 Correct 2 ms 7260 KB Output is correct
72 Correct 3 ms 9564 KB Output is correct
73 Correct 3 ms 9484 KB Output is correct
74 Correct 3 ms 9564 KB Output is correct
75 Correct 3 ms 9564 KB Output is correct
76 Correct 2 ms 9564 KB Output is correct
77 Correct 3 ms 9496 KB Output is correct
78 Correct 3 ms 9564 KB Output is correct
79 Correct 3 ms 9564 KB Output is correct
80 Correct 40 ms 14096 KB Output is correct
81 Correct 40 ms 14172 KB Output is correct
82 Correct 39 ms 14420 KB Output is correct
83 Correct 39 ms 14428 KB Output is correct
84 Correct 2 ms 9564 KB Output is correct
85 Correct 2 ms 9564 KB Output is correct
86 Correct 2 ms 9464 KB Output is correct
87 Correct 3 ms 9496 KB Output is correct
88 Correct 3 ms 9584 KB Output is correct
89 Correct 2 ms 9564 KB Output is correct
90 Correct 4 ms 9564 KB Output is correct
91 Correct 4 ms 9564 KB Output is correct
92 Correct 3 ms 9564 KB Output is correct
93 Correct 2 ms 9564 KB Output is correct
94 Correct 2 ms 9452 KB Output is correct
95 Correct 3 ms 9704 KB Output is correct
96 Correct 2 ms 9308 KB Output is correct
97 Correct 2 ms 9308 KB Output is correct
98 Correct 2 ms 9308 KB Output is correct
99 Correct 2 ms 9308 KB Output is correct
100 Correct 2 ms 9308 KB Output is correct
101 Correct 2 ms 9448 KB Output is correct
102 Correct 2 ms 9308 KB Output is correct
103 Correct 2 ms 9464 KB Output is correct
104 Correct 5 ms 10332 KB Output is correct
105 Correct 11 ms 12224 KB Output is correct
106 Correct 2 ms 9308 KB Output is correct
107 Correct 21 ms 13340 KB Output is correct
108 Correct 27 ms 15324 KB Output is correct
109 Correct 2 ms 9564 KB Output is correct
110 Correct 34 ms 16924 KB Output is correct
111 Correct 38 ms 19172 KB Output is correct
112 Correct 2 ms 9308 KB Output is correct
113 Correct 53 ms 22836 KB Output is correct
114 Correct 17 ms 11864 KB Output is correct
115 Incorrect 14 ms 11864 KB Output isn't correct
116 Halted 0 ms 0 KB -