Submission #972424

# Submission time Handle Problem Language Result Execution time Memory
972424 2024-04-30T12:00:07 Z Nika533 Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#include "dreaming.h"
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>

using namespace std;

const int NMAX=1e5+5;
int n,m,fix[NMAX],mx[NMAX],next[NMAX];
vector<pii> g[NMAX];

void dfs(int x, int p) {
	mx[x]=0; next[x]=-1; fix[x]=1;
	if (x!=p && g[x].size()==1) return;
	for (auto A:g[x]) {
		int y=A.f,w=A.s;
		if (y==p) continue;
		dfs(y,x);
		if (mx[x]<w+mx[y]) {
			mx[x]=w+mx[y];
			next[x]=y;
		}
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	n=N; m=M;
	for (int i=0; i<m; i++) {
		int a=A[i],b=B[i],c=T[i];
		g[a].pb({b,c}); g[b].pb({a,c});
	}
	
	//subtask 1 & 2 & 3
	
	int ans=L;
	
	for (int i=0; i<n; i++) {
		if (fix[i]==0) {
			
			vector<int> v;
			
			dfs(i,i);
			int j=i;
			while (j>=0) {
				v.pb(j); j=next[j]; 
			}
			
			int st=v.back(); v.clear();
			
			dfs(st,st);
			j=st;
			while (j>=0) {
				v.pb(j); j=next[j];
			}
			
			int d=mx[st],mn=1e9;
			for (auto x:v) {
				mn=min(mn,max(mx[x],d-mx[x]));
			}
			ans+=mn;
		}
	}
	return ans;
}

Compilation message

dreaming.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:20:11: error: reference to 'next' is ambiguous
   20 |  mx[x]=0; next[x]=-1; fix[x]=1;
      |           ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from dreaming.cpp:2:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
dreaming.cpp:16:28: note:                 'int next [100005]'
   16 | int n,m,fix[NMAX],mx[NMAX],next[NMAX];
      |                            ^~~~
dreaming.cpp:28:4: error: reference to 'next' is ambiguous
   28 |    next[x]=y;
      |    ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from dreaming.cpp:2:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
dreaming.cpp:16:28: note:                 'int next [100005]'
   16 | int n,m,fix[NMAX],mx[NMAX],next[NMAX];
      |                            ^~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:52:16: error: reference to 'next' is ambiguous
   52 |     v.pb(j); j=next[j];
      |                ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from dreaming.cpp:2:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
dreaming.cpp:16:28: note:                 'int next [100005]'
   16 | int n,m,fix[NMAX],mx[NMAX],next[NMAX];
      |                            ^~~~
dreaming.cpp:60:16: error: reference to 'next' is ambiguous
   60 |     v.pb(j); j=next[j];
      |                ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from dreaming.cpp:2:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
dreaming.cpp:16:28: note:                 'int next [100005]'
   16 | int n,m,fix[NMAX],mx[NMAX],next[NMAX];
      |                            ^~~~