submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s899226478
p04049
C++
#include<iostream> #include<algorithm> using namespace std; const double pi=acos(-1); const int dx[]={0,1,0,-1}; const int dy[]={1,0,-1,0}; #define ll long long #define inf int(1e9+7) #define pb push_back #define mp make_pair int n,k; vector<int>g[2005]; int dfs(int x,int p,int deepth,int mx) { int ans=1; if(deepth!=mx) { for(int i=0;i<g[x].size();i++) if(i!=p) ans+=dfs(i,x,deepth+1,mx); } return ans; } int main() { cin>>n>>k; for(int i=0;i<n-1;i++) { int x,y; cin>>x>>y; g[x].pb(y); g[y].pb(x); } int ans=0; if(k%2==0) for(int i=1;i<=n;i++) ans=max(ans,dfs(i,-1,0,k/2)); else { for(int i=1;i<=n;i++) for(int j=0;j<g[i].size();j++) ans=max(ans,dfs(i,g[i][j],0,k/2)+dfs(g[i][j],i,0,k/2)); } cout<<n-ans; return 0; }
a.cc:4:17: error: 'acos' was not declared in this scope 4 | const double pi=acos(-1); | ^~~~ a.cc:12:1: error: 'vector' does not name a type 12 | vector<int>g[2005]; | ^~~~~~ a.cc: In function 'int dfs(int, int, int, int)': a.cc:18:31: error: 'g' was not declared in this scope 18 | for(int i=0;i<g[x].size();i++) | ^ a.cc: In function 'int main()': a.cc:31:17: error: 'g' was not declared in this scope 31 | g[x].pb(y); | ^ a.cc:41:39: error: 'g' was not declared in this scope 41 | for(int j=0;j<g[i].size();j++) | ^
s933354400
p04049
C
//#include "pch.h" #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <vector> //#include <set> //#include <map> //#include <iostream> #define ll long long #define fri(n) for(i=0;i<(n);i++) #define frj(n) for(j=0;j<(n);i++) #define min(p,q) ((p)<(q)?(p):(q)) #define max(p,q) ((p)>(q)?(p):(q)) #define INF 1000000000000//10^12 using namespace std; int m; int come[2050]; vector<int> graph[2050]; void init(void){ int i; for(i=0;i<2050;i++){ come[i]=0; } } int evensearch(int a,int d){ int i; int sum=1; if(come[a]==1) return 0; if(d==m/2) return 1; for(i=0;i<graph[a].size();i++){ sum=sum+evensearch(graph[a][i],d+1); } return sum; } int oddsearch(int a,int b,int d){ int i; int sum=1; if(come[a]==1||a==b) return 0; if(d==m/2) return 1; come[a]=1; for(i=0;i<graph[a].size();i++){ sum=sum+oddsearch(graph[a][i],b,d+1); } // printf("%d->%d\n",a,sum); return sum; } int main(void) { //変数の宣言 int n; // int m; int a[2050]; int b[2050]; // //よく使う変数 int i,j,k,l; int flag=0; int ans=0; int count=0; ll int temp,temp1,temp2; int max,min; int len; int sum=0; //データの読み込み scanf("%d %d",&n,&m); // scanf_s("%d %d",&n,&m); for(i=0;i<n-1;i++){ scanf("%d %d",&a[i],&b[i]); // scanf_s("%d %d",&a[i],&b[i]); graph[a[i]].push_back(b[i]); graph[b[i]].push_back(a[i]); } // printf("nは%dです\n", n); // printf("データの読み込み終了\n"); //実際の処理 if(m%2==0){ for(i=1;i<=n;i++){ init(); ans=max(ans,evensearch(i,0)); } }else{ for(i=0;i<n-1;i++){ init(); // ans=max(ans,oddsearch(a[i],b[i],0)+oddsearch(b[i],a[i],0)); temp=oddsearch(a[i],b[i],0); temp=temp+oddsearch(b[i],a[i],0); ans=max(ans,temp); // printf("(%d,%d)-->left->%d,right->%d\n",a[i],b[i],oddsearch(a[i],b[i],0),oddsearch(b[i],a[i],0)); } } // printf("計算部分終了\n"); //出力 printf("%d",n-ans); // printf("結果の出力終了\n"); return 0; }
main.c:8:10: fatal error: vector: No such file or directory 8 | #include <vector> | ^~~~~~~~ compilation terminated.
s317017859
p04049
C++
#include<bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define vi vector<ll> #define vvi vector<vi> #define substr(s,f,t) (s.substr(f-1,t-f+1)) #define ALL(a) (a).begin(),(a).end() #define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl; #define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl; using namespace std; struct Grid{ll x,y,t;}; struct Edge{ll to,cost;}; struct Graph{vector<vector<Edge>>E;int V; const ll Inf = llINF;const int MAX_V=201010;vector<ll>d; Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;} void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;} void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});} }; vvi E(10010); ll n,k; vector<pair<ll,pair<ll,ll>>> par; int main(){ cin.tie(0); ios::sync_with_stdio(false); cin>>n>>k; par.resize(n); for(int i=0;i<n+10;i++)par[i]=-1; for(int i=0;i<n-1;i++){ ll a,b;cin>>a>>b; E[--a].pb(--b); E[b].pb(a); } for(int i=0;i<n;i++){ if(E[i].size()!=1)continue; if(E[E[i][0]].size()>2)continue; queue<pair<ll,ll>>que; que.push(mp(i,0)); par[i]=mp(0,mp(i,-1)); while(!que.empty()){ pair<ll,ll>pll=que.front(); que.pop(); for(int j=0;j<E[pll.F].size();j++){ if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ par[E[pll.F][j]]=mp(pll.S+1,mp(E[pll.F][j],pll.F)); que.push(mp(E[pll.F][j],pll.S)); } } } break; } sort(ALL(par)); ll ans=0; ll le=0,ri=par[n-1].F; while(ri-le>k){ int lcnt=0,rcnt=0; for(int i=0;i<n;i++) if(par[i].F==le)lcnt++; for(int i=0;i<n;i++) if(par[i].F==ri)rcnt++; if(lcnt>rcnt){ ans+=rcnt; ri--; }else{ ans+=lcnt; le++; } } cout<<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:34:34: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >, std::pair<long long int, std::pair<long long int, long long int> > >::value_type' {aka 'std::pair<long long int, std::pair<long long int, long long int> >'} and 'int') 34 | for(int i=0;i<n+10;i++)par[i]=-1; | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:946:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = long long int; _T2 = std::pair<long long int, long long int>]' 946 | operator=(const pair<_U1, _U2>& __p) | ^~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:946:9: note: template argument deduction/substitution failed: a.cc:34:34: note: mismatched types 'const std::pair<_T1, _T2>' and 'int' 34 | for(int i=0;i<n+10;i++)par[i]=-1; | ^ /usr/include/c++/14/bits/stl_pair.h:957:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = long long int; _T2 = std::pair<long long int, long long int>]' 957 | operator=(pair<_U1, _U2>&& __p) | ^~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:957:9: note: template argument deduction/substitution failed: a.cc:34:34: note: mismatched types 'std::pair<_T1, _T2>' and 'int' 34 | for(int i=0;i<n+10;i++)par[i]=-1; | ^ /usr/include/c++/14/bits/stl_pair.h:921:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = long long int; _T2 = std::pair<long long int, long long int>; std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&> = const std::pair<long long int, std::pair<long long int, long long int> >&]' 921 | operator=(__conditional_t<__and_<is_copy_assignable<_T1>, | ^~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:923:65: note: no known conversion for argument 1 from 'int' to 'std::__conditional_t<true, const std::pair<long long int, std::pair<long long int, long long int> >&, const std::__nonesuch&>' {aka 'const std::pair<long long int, std::pair<long long int, long long int> >&'} 921 | operator=(__conditional_t<__and_<is_copy_assignable<_T1>, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 922 | is_copy_assignable<_T2>>::value, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 923 | const pair&, const __nonesuch&> __p) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/stl_pair.h:931:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = long long int; _T2 = std::pair<long long int, long long int>; std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&> = std::pair<long long int, std::pair<long long int, long long int> >&&]' 931 | operator=(__conditional_t<__and_<is_move_assignable<_T1>, | ^~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:933:55: note: no known conversion for argument 1 from 'int' to 'std::__conditional_t<true, std::pair<long long int, std::pair<long long int, long long int> >&&, std::__nonesuch&&>' {aka 'std::pair<long long int, std::pair<long long int, long long int> >&&'} 931 | operator=(__conditional_t<__and_<is_move_assignable<_T1>, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 932 | is_move_assignable<_T2>>::value, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 933 | pair&&, __nonesuch&&> __p) | ~~~~~~~~~~~~~~~~~~~~~~^~~ a.cc:50:28: error: no match for 'operator!=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >, std::pair<long long int, std::pair<long long int, long long int> > >::value_type' {aka 'std::pair<long long int, std::pair<long long int, long long int> >'} and 'std::pair<int, std::pair<int, int> >') 50 | if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ In file included from /usr/include/c++/14/regex:68, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181: /usr/include/c++/14/bits/regex.h:1132:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)' 1132 | operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1132:5: note: template argument deduction/substitution failed: a.cc:50:42: note: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >, std::pair<long long int, std::pair<long long int, long long int> > >::value_type' {aka 'std::pair<long long int, std::pair<long long int, long long int> >'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 50 | if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ | ^ /usr/include/c++/14/bits/regex.h:1212:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)' 1212 | operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1212:5: note: template argument deduction/substitution failed: a.cc:50:42: note: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >, std::pair<long long int, std::pair<long long int, long long int> > >::value_type' {aka 'std::pair<long long int, std::pair<long long int, long long int> >'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' 50 | if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ | ^ /usr/include/c++/14/bits/regex.h:1305:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)' 1305 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1305:5: note: template argument deduction/substitution failed: a.cc:50:42: note: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >, std::pair<long long int, std::pair<long long int, long long int> > >::value_type' {aka 'std::pair<long long int, std::pair<long long int, long long int> >'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 50 | if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ | ^ /usr/include/c++/14/bits/regex.h:1379:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)' 1379 | operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1379:5: note: template argument deduction/substitution failed: a.cc:50:42: note: 'std::pair<int, std::pair<int, int> >' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 50 | if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ | ^ /usr/include/c++/14/bits/regex.h:1473:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)' 1473 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1473:5: note: template argument deduction/substitution failed: a.cc:50:42: note: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, std::pair<long long int, long long int> > >, std::pair<long long int, std::pair<long long int, long long int> > >::value_type' {aka 'std::pair<long long int, std::pair<long long int, long long int> >'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 50 | if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ | ^ /usr/include/c++/14/bits/regex.h:1547:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)' 1547 | operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1547:5: note: template argument deduction/substitution failed: a.cc:50:42: note: 'std::pair<int, std::pair<int, int> >' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 50 | if(par[E[pll.F][j]]!=mp(0,mp(0,0))){ | ^ /usr/include/c++/14/bits
s975895642
p04049
C++
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <string> #include <cmath> #include <iomanip> #include <queue> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cassert> #include <cstring> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int dx[] = {0, 0, 1, -1}; constexpr int dy[] = {1, -1, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k, a[2010], b[2010]; V g[2010]; cin >> n >> k; REP(i, n - 1) { cin >> a[i] >> b[i]; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } int res = INT_MAX; for (int i = 1; i <= n; i++) { int cnt = 1; queue<int> q; q.push(i); int dis[2100]; fill(dis, dis + n + 1, -1); dis[i] = 0; while (q.size()) { int p = q.front(); q.pop(); for (int j : g[p]) { if (dis[p] + 1 <= k / 2 && dis[j] == -1) { cnt++; dis[j] = dis[p] + 1; if (dis[p] + 1 < k / 2) q.push(j); } } } res = min(n - cnt, res); } if (k % 2 && res) res--; cout << res << endl; return 0; }
a.cc: In function 'int main()': a.cc:49:15: error: 'INT_MAX' was not declared in this scope 49 | int res = INT_MAX; | ^~~~~~~ a.cc:15:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 14 | #include <cstring> +++ |+#include <climits> 15 |
s015338893
p04049
C++
#include<queue> #include<cstdio> #include<algorithm> using namespace std; const int MAXN = 2000; struct edge{ int to; edge *nxt; }edges[MAXN*2 + 5], *adj[MAXN + 5], *ecnt = &edges[0]; void addedge(int u, int v) { edge *p = (++ecnt); p->to = v, p->nxt = adj[u], adj[u] = p; p = (++ecnt); p->to = u, p->nxt = adj[v], adj[v] = p; } queue<int>que; int dis[MAXN + 5], vis[MAXN + 5], N, K; int solve() { int ret = 0; while( !que.empty() ) { int f = que.front(); que.pop(); if( dis[f] > K/2 ) ret++; for(edge *p=adj[f];p!=NULL;p=p->nxt) { if( !vis[p->to] ) { vis[p->to] = true; dis[p->to] = dis[f] + 1; que.push(p->to); } } } return ret; } int main() { scanf("%d%d", &N, &K); for(int i=1;i<N;i++) { int A, B; scanf("%d%d", &A, &B); addedge(A, B); } int ans = MAXN + 5; if( K % 2 == 0 ) { for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); ans = min(ans, solve()); } } else { for(int i=1;i<=N;i++) { for(edge *p=adj[i];p!=NULL;p=p->nxt) { if( i > p->to ) continue; for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); vis[p->to] = true; que.push(p->to); ans = min(ans, solve()); } } } printf("%d\n", ans); }
a.cc:1:17: warning: extra tokens at end of #include directive 1 | #include<queue> #include<cstdio> | ^ a.cc: In function 'int main()': a.cc:3:594: error: 'scanf' was not declared in this scope 3 | using namespace std; const int MAXN = 2000; struct edge{ int to; edge *nxt; }edges[MAXN*2 + 5], *adj[MAXN + 5], *ecnt = &edges[0]; void addedge(int u, int v) { edge *p = (++ecnt); p->to = v, p->nxt = adj[u], adj[u] = p; p = (++ecnt); p->to = u, p->nxt = adj[v], adj[v] = p; } queue<int>que; int dis[MAXN + 5], vis[MAXN + 5], N, K; int solve() { int ret = 0; while( !que.empty() ) { int f = que.front(); que.pop(); if( dis[f] > K/2 ) ret++; for(edge *p=adj[f];p!=NULL;p=p->nxt) { if( !vis[p->to] ) { vis[p->to] = true; dis[p->to] = dis[f] + 1; que.push(p->to); } } } return ret; } int main() { scanf("%d%d", &N, &K); for(int i=1;i<N;i++) { int A, B; scanf("%d%d", &A, &B); addedge(A, B); } int ans = MAXN + 5; if( K % 2 == 0 ) { for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); ans = min(ans, solve()); } } else { for(int i=1;i<=N;i++) { for(edge *p=adj[i];p!=NULL;p=p->nxt) { if( i > p->to ) continue; for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); vis[p->to] = true; que.push(p->to); ans = min(ans, solve()); } } } printf("%d\n", ans); } | ^~~~~ a.cc:3:1109: error: 'printf' was not declared in this scope 3 | using namespace std; const int MAXN = 2000; struct edge{ int to; edge *nxt; }edges[MAXN*2 + 5], *adj[MAXN + 5], *ecnt = &edges[0]; void addedge(int u, int v) { edge *p = (++ecnt); p->to = v, p->nxt = adj[u], adj[u] = p; p = (++ecnt); p->to = u, p->nxt = adj[v], adj[v] = p; } queue<int>que; int dis[MAXN + 5], vis[MAXN + 5], N, K; int solve() { int ret = 0; while( !que.empty() ) { int f = que.front(); que.pop(); if( dis[f] > K/2 ) ret++; for(edge *p=adj[f];p!=NULL;p=p->nxt) { if( !vis[p->to] ) { vis[p->to] = true; dis[p->to] = dis[f] + 1; que.push(p->to); } } } return ret; } int main() { scanf("%d%d", &N, &K); for(int i=1;i<N;i++) { int A, B; scanf("%d%d", &A, &B); addedge(A, B); } int ans = MAXN + 5; if( K % 2 == 0 ) { for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); ans = min(ans, solve()); } } else { for(int i=1;i<=N;i++) { for(edge *p=adj[i];p!=NULL;p=p->nxt) { if( i > p->to ) continue; for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); vis[p->to] = true; que.push(p->to); ans = min(ans, solve()); } } } printf("%d\n", ans); } | ^~~~~~ a.cc:3:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' 2 | #include<algorithm> +++ |+#include <cstdio> 3 | using namespace std; const int MAXN = 2000; struct edge{ int to; edge *nxt; }edges[MAXN*2 + 5], *adj[MAXN + 5], *ecnt = &edges[0]; void addedge(int u, int v) { edge *p = (++ecnt); p->to = v, p->nxt = adj[u], adj[u] = p; p = (++ecnt); p->to = u, p->nxt = adj[v], adj[v] = p; } queue<int>que; int dis[MAXN + 5], vis[MAXN + 5], N, K; int solve() { int ret = 0; while( !que.empty() ) { int f = que.front(); que.pop(); if( dis[f] > K/2 ) ret++; for(edge *p=adj[f];p!=NULL;p=p->nxt) { if( !vis[p->to] ) { vis[p->to] = true; dis[p->to] = dis[f] + 1; que.push(p->to); } } } return ret; } int main() { scanf("%d%d", &N, &K); for(int i=1;i<N;i++) { int A, B; scanf("%d%d", &A, &B); addedge(A, B); } int ans = MAXN + 5; if( K % 2 == 0 ) { for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); ans = min(ans, solve()); } } else { for(int i=1;i<=N;i++) { for(edge *p=adj[i];p!=NULL;p=p->nxt) { if( i > p->to ) continue; for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); vis[p->to] = true; que.push(p->to); ans = min(ans, solve()); } } } printf("%d\n", ans); }
s667697533
p04049
C++
#include<queue> #include<cstdio> #include<algorithm> using namespace std; const int MAXN = 2000; struct edge{ int to; edge *nxt; }edges[MAXN*2 + 5], *adj[MAXN + 5], *ecnt = &edges[0]; void addedge(int u, int v) { edge *p = (++ecnt); p->to = v, p->nxt = adj[u], adj[u] = p; p = (++ecnt); p->to = u, p->nxt = adj[v], adj[v] = p; } queue<int>que; int dis[MAXN + 5], vis[MAXN + 5], N, K; int solve() { int ret = 0; while( !que.empty() ) { int f = que.front(); que.pop(); if( dis[f] > K/2 ) ret++; for(edge *p=adj[f];p!=NULL;p=p->nxt) { if( !vis[p->to] ) { vis[p->to] = true; dis[p->to] = dis[f] + 1; que.push(p->to); } } } return ret; } int main() { scanf("%d%d", &N, &K); for(int i=1;i<N;i++) { int A, B; scanf("%d%d", &A, &B); addedge(A, B); } int ans = MAXN + 5; if( K % 2 == 0 ) { for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); ans = min(ans, solve()); } } else { for(int i=1;i<=N;i++) { for(edge *p=adj[i];p!=NULL;p=p->nxt) { if( i > p->to ) continue; for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); vis[p->to] = true; que.push(p->to); ans = min(ans, solve()); } } } printf("%d\n", ans); }
a.cc:1:17: warning: extra tokens at end of #include directive 1 | #include<queue> #include<cstdio> #include<algorithm> using namespace std; const int MAXN = 2000; struct edge{ int to; edge *nxt; }edges[MAXN*2 + 5], *adj[MAXN + 5], *ecnt = &edges[0]; void addedge(int u, int v) { edge *p = (++ecnt); p->to = v, p->nxt = adj[u], adj[u] = p; p = (++ecnt); p->to = u, p->nxt = adj[v], adj[v] = p; } queue<int>que; int dis[MAXN + 5], vis[MAXN + 5], N, K; int solve() { int ret = 0; while( !que.empty() ) { int f = que.front(); que.pop(); if( dis[f] > K/2 ) ret++; for(edge *p=adj[f];p!=NULL;p=p->nxt) { if( !vis[p->to] ) { vis[p->to] = true; dis[p->to] = dis[f] + 1; que.push(p->to); } } } return ret; } int main() { scanf("%d%d", &N, &K); for(int i=1;i<N;i++) { int A, B; scanf("%d%d", &A, &B); addedge(A, B); } int ans = MAXN + 5; if( K % 2 == 0 ) { for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); ans = min(ans, solve()); } } else { for(int i=1;i<=N;i++) { for(edge *p=adj[i];p!=NULL;p=p->nxt) { if( i > p->to ) continue; for(int j=1;j<=N;j++) { vis[j] = false; dis[j] = 0; } vis[i] = true; que.push(i); vis[p->to] = true; que.push(p->to); ans = min(ans, solve()); } } } printf("%d\n", ans); } | ^ /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
s475765262
p04049
C++
#include <iostream> #include <fstream> #include <cmath> #include <cstdlib> #include <ctime> #include <algorithm> #include <numeric> #include <functional> #include <string> #include <vector> #include <bitset> #include <map> #include <set> #include <stack> #include <queue> #include <deque> using namespace std; using ll = long long; template<class T> using V = vector<T>; template<class T, class U> using P = pair<T, U>; #define REP(i,n) for(int i = 0; i < int(n); i++) #define FOR(i, m, n) for(int i = int(m);i < int(n);i++) #define ALL(obj) (obj).begin(),(obj).end() const ll MOD = (ll)1e9 + 7; const ll HINF = (ll)1e18; const ll LINF = (ll)1e9; const long double PI = 3.1415926535897932384626433; template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } else return; } template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; } template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; } template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; } template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } void print(void) { cout << endl; } template <class Head> void print(Head&& head) { cout << head; print(); } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); } void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; } void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; } void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; } const int MAXN = 2000; int N;ll K; V<V<ll>> dist(MAXN, V<ll>(MAXN, -1)); V<V<ll>> edge(MAXN); void bfs(int s){ queue<int> q; q.push(s); dist[s][s] = 0; while (!q.empty()) { int from = q.front(); q.pop(); for(auto to: edge[from]){ if(dist[s][to]==-1){ q.push(to); dist[s][to] = dist[s][from]+1; } } } return; } template<class T> class Segment_Tree_Range_Maximum_Query { public: int N; T ini; vector<T> node; void init(const vector<T> & ar, const T iini = 0) { ini = iini; for (N = 1; N < ar.size(); N *= 2); node.resize(2 * N - 1, ini); for (int i = 0; i<ar.size(); ++i) node[i + N - 1] = ar[i]; for (int i = N - 2; i >= 0; --i) node[i] = max(node[2 * i + 1], node[2 * i + 2]); } void update(int idx, const T var) { idx += (N - 1); node[idx] = var; while (idx > 0) { idx = (idx - 1) / 2; node[idx] = max(node[2 * idx + 1], node[2 * idx + 2]); } } T getvar(const int a, const int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; if (r <= a || b <= l) return ini; if (a <= l && r <= b) return node[k]; T vl = getvar(a, b, 2 * k + 1, l, (l + r) / 2); T vr = getvar(a, b, 2 * k + 2, (l + r) / 2, r); return max(vl, vr); } }; template<class T> class Segment_Tree_Range_Sum_Query { public: int N; T ini; vector<T> node; void init(const vector<T> & ar, const T iini = 0){ ini = iini; for (N = 1; N < ar.size(); N *= 2); node.resize(2 * N - 1, ini); for (int i = 0; i<ar.size(); ++i) node[i + N - 1] = ar[i]; for (int i = N - 2; i >= 0; --i) node[i] = node[2 * i + 1] + node[2 * i + 2]; } void update(int idx, const T var) { idx += (N - 1); node[idx] += var; while (idx > 0) { idx = (idx - 1) / 2; node[idx] = node[2 * idx + 1] + node[2 * idx + 2]; } } T getvar(const int a, const int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; if (r <= a || b <= l) return ini; if (a <= l && r <= b) return node[k]; T vl = getvar(a, b, 2 * k + 1, l, (l + r) / 2); T vr = getvar(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; int main() { cin >> N >> K; REP(i,N-1){ int A, B; scanf_s("%d%d", &A, &B); A--; B--; edge[A].push_back(B); edge[B].push_back(A); } REP(i, N) bfs(i); V<Segment_Tree_Range_Sum_Query<ll>> RSQ(N); V<Segment_Tree_Range_Maximum_Query<ll>> RMQ(N); REP(i,N){ RSQ[i].init(dist[i]); RMQ[i].init(dist[i]); } Segment_Tree_Range_Maximum_Query<P<P<ll, ll>, int>> Seg; V<P<P<ll, ll>, int>> a(N); REP(i, N) a[i] = { { RMQ[i].getvar(0,N), RSQ[i].getvar(0, N) },i }; Seg.init(a, { {0,0},0 }); REP(i, N) { P<P<ll, ll>, int> p = Seg.getvar(0, N); ll maxi = p.first.first; ll sum = p.first.second; int idx = p.second; if (maxi <= K) { cout << i << endl; return 0; } REP(j, N) { RMQ[idx].update(j, 0); RSQ[j].update(idx, -dist[j][idx]); RMQ[j].update(idx, 0); Seg.update(j, { { RMQ[j].getvar(0,N), RSQ[j].getvar(0, N) },j }); } } return 0; }
a.cc: In function 'int main()': a.cc:179:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'? 179 | scanf_s("%d%d", &A, &B); | ^~~~~~~ | scanf
s099656322
p04049
C++
#include <iostream> #include <fstream> #include <cmath> #include <cstdlib> #include <ctime> #include <algorithm> #include <numeric> #include <functional> #include <string> #include <vector> #include <bitset> #include <map> #include <set> #include <stack> #include <queue> #include <deque> using namespace std; using ll = long long; template<class T> using V = vector<T>; template<class T, class U> using P = pair<T, U>; #define REP(i,n) for(int i = 0; i < int(n); i++) #define FOR(i, m, n) for(int i = int(m);i < int(n);i++) #define ALL(obj) (obj).begin(),(obj).end() const ll MOD = (ll)1e9 + 7; const ll HINF = (ll)1e18; const ll LINF = (ll)1e9; const long double PI = 3.1415926535897932384626433; template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } else return; } template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; } template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; } template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; } template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } void print(void) { cout << endl; } template <class Head> void print(Head&& head) { cout << head; print(); } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); } void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; } void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; } void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; } const int MAXN = 2000; int N;ll K; V<V<ll>> dist(MAXN, V<ll>(MAXN, -1)); V<V<ll>> edge(MAXN); void bfs(int s){ queue<int> q; q.push(s); dist[s][s] = 0; while (!q.empty()) { int from = q.front(); q.pop(); for(auto to: edge[from]){ if(dist[s][to]==-1){ q.push(to); dist[s][to] = dist[s][from]+1; } } } return; } template<class T> class Segment_Tree_Range_Maximum_Query { public: int N; T ini; vector<T> node; void init(const vector<T> & ar, const T iini = 0) { ini = iini; for (N = 1; N < ar.size(); N *= 2); node.resize(2 * N - 1, ini); for (int i = 0; i<ar.size(); ++i) node[i + N - 1] = ar[i]; for (int i = N - 2; i >= 0; --i) node[i] = max(node[2 * i + 1], node[2 * i + 2]); } void update(int idx, const T var) { idx += (N - 1); node[idx] = var; while (idx > 0) { idx = (idx - 1) / 2; node[idx] = max(node[2 * idx + 1], node[2 * idx + 2]); } } T getvar(const int a, const int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; if (r <= a || b <= l) return ini; if (a <= l && r <= b) return node[k]; T vl = getvar(a, b, 2 * k + 1, l, (l + r) / 2); T vr = getvar(a, b, 2 * k + 2, (l + r) / 2, r); return max(vl, vr); } }; template<class T> class Segment_Tree_Range_Sum_Query { public: int N; T ini; vector<T> node; void init(const vector<T> & ar, const T iini = 0){ ini = iini; for (N = 1; N < ar.size(); N *= 2); node.resize(2 * N - 1, ini); for (int i = 0; i<ar.size(); ++i) node[i + N - 1] = ar[i]; for (int i = N - 2; i >= 0; --i) node[i] = node[2 * i + 1] + node[2 * i + 2]; } void update(int idx, const T var) { idx += (N - 1); node[idx] += var; while (idx > 0) { idx = (idx - 1) / 2; node[idx] = node[2 * idx + 1] + node[2 * idx + 2]; } } T getvar(const int a, const int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; if (r <= a || b <= l) return ini; if (a <= l && r <= b) return node[k]; T vl = getvar(a, b, 2 * k + 1, l, (l + r) / 2); T vr = getvar(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; int main() { cin >> N >> K; REP(i,N-1){ int A, B; scanf_s("%d%d", &A, &B); A--; B--; edge[A].push_back(B); edge[B].push_back(A); } REP(i, N) bfs(i); V<Segment_Tree_Range_Sum_Query<ll>> RSQ(N); V<Segment_Tree_Range_Maximum_Query<ll>> RMQ(N); REP(i,N){ RSQ[i].init(dist[i]); RMQ[i].init(dist[i]); } Segment_Tree_Range_Maximum_Query<P<P<ll, ll>, int>> Seg; V<P<P<ll, ll>, int>> a(N); REP(i, N) a[i] = { { RMQ[i].getvar(0,N), RSQ[i].getvar(0, N) },i }; Seg.init(a, { {0,0},0 }); REP(i, N) { P<P<ll, ll>, int> p = Seg.getvar(0, N); ll maxi = p.first.first; ll sum = p.first.second; int idx = p.second; if (maxi <= K) { cout << i << endl; return 0; } REP(j, N) { RSQ[idx].update(j, -dist[idx][j]); RMQ[idx].update(j, 0); RSQ[j].update(idx, -dist[j][idx]); RMQ[j].update(idx, 0); Seg.update(j, { { RMQ[j].getvar(0,N), RSQ[j].getvar(0, N) },j }); } } return 0; }
a.cc: In function 'int main()': a.cc:179:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'? 179 | scanf_s("%d%d", &A, &B); | ^~~~~~~ | scanf
s692618982
p04049
C++
#include<bits/stdc++.h> using namespace std; const int MAXN=4000+5; int first[MAXN*2],next[MAXN*2],get[MAXN*2],have1,have2; int deep[MAXN],fa[MAXN],have[MAXN]; int n,k,top,ans,now,kkk,maxkkk; inline void add(int x,int y){get[++top]=y;next[top]=first[x];first[x]=top;} void dfs(int x,int f,int d){ deep[x]=d; fa[x]=f; if (deep[x]>k/2) ++now; for (int i=first[x];i;i=next[i]){ int v=get[i]; if (v==f) continue; dfs(v,x,d+1); } } void dfs1(int x,int f,int d){ deep[x]=d; fa[x]=f; if (deep[x]>k/2) ++now; for (int i=first[x];i;i=next[i]){ int v=get[i]; if (v==f) continue; dfs1(v,x,d+1); } } void find(int x,int f){ if (deep[x]==(k/2)+1) ++kkk; if (deep[x]>=(k/2)+1) return; for (int i=first[x];i;i=next[i]){ int v=get[i]; if (v==f) continue; find(v,x); } } int main(){ //freopen(".in","r",stdin); scanf("%d%d",&n,&k); ans=n; if (k>=n){ printf("0"); return 0; } int x,y; for (int i=1;i<n;++i){ scanf("%d%d",&x,&y); add(x,y);add(y,x); ++have[x]; ++have[y]; } for (int i=1;i<=n;++i){ if (have[i]==1) ++have1; if (have[i]==2) ++have2; } if (have1==2&&have2==(n-2)){ printf("%d",max(0,n-k)); return 0; } if (k%2==1){ for (int i=1;i<=n;++i){ memset(deep,0,sizeof(deep)); now=0; dfs1(i,0,0); maxkkk=0; for (int j=first[i];j;j=next[j]){ kkk=0; find(get[j],i); maxkkk=max(maxkkk,kkk); } ans=min(ans,now-maxkkk); } printf("%d",ans-1); return 0; } else { for (int i=1;i<=n;++i){ memset(deep,0,sizeof(deep)); now=0; dfs(i,0,0); ans=min(ans,now); } printf("%d",ans); return 0; } }
a.cc: In function 'void add(int, int)': a.cc:7:30: error: reference to 'get' is ambiguous 7 | inline void add(int x,int y){get[++top]=y;next[top]=first[x];first[x]=top;} | ^~~ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80, from a.cc:1: /usr/include/c++/14/variant:1180:5: note: candidates are: 'template<class _Tp, class ... _Types> constexpr const _Tp&& std::get(const variant<_Types ...>&&)' 1180 | get(const variant<_Types...>&& __v) | ^~~ /usr/include/c++/14/variant:1170:5: note: 'template<class _Tp, class ... _Types> constexpr const _Tp& std::get(const variant<_Types ...>&)' 1170 | get(const variant<_Types...>& __v) | ^~~ /usr/include/c++/14/variant:1160:5: note: 'template<class _Tp, class ... _Types> constexpr _Tp&& std::get(variant<_Types ...>&&)' 1160 | get(variant<_Types...>&& __v) | ^~~ /usr/include/c++/14/variant:1150:5: note: 'template<class _Tp, class ... _Types> constexpr _Tp& std::get(variant<_Types ...>&)' 1150 | get(variant<_Types...>& __v) | ^~~ /usr/include/c++/14/variant:1748:5: note: 'template<long unsigned int _Np, class ... _Types> constexpr std::variant_alternative_t<_Np, std::variant<_Types ...> >&& std::get(const variant<_Types ...>&&)' 1748 | get(const variant<_Types...>&& __v) | ^~~ /usr/include/c++/14/variant:1737:5: note: 'template<long unsigned int _Np, class ... _Types> constexpr std::variant_alternative_t<_Np, std::variant<_Types ...> >& std::get(const variant<_Types ...>&)' 1737 | get(const variant<_Types...>& __v) | ^~~ /usr/include/c++/14/variant:1726:5: note: 'template<long unsigned int _Np, class ... _Types> constexpr std::variant_alternative_t<_Np, std::variant<_Types ...> >&& std::get(variant<_Types ...>&&)' 1726 | get(variant<_Types...>&& __v) | ^~~ /usr/include/c++/14/variant:1715:5: note: 'template<long unsigned int _Np, class ... _Types> constexpr std::variant_alternative_t<_Np, std::variant<_Types ...> >& std::get(variant<_Types ...>&)' 1715 | get(variant<_Types...>& __v) | ^~~ In file included from /usr/include/c++/14/bits/memory_resource.h:47, from /usr/include/c++/14/string:68, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52: /usr/include/c++/14/tuple:2517:5: note: 'template<class _Tp, class ... _Types> constexpr const _Tp&& std::get(const tuple<_Elements ...>&&)' 2517 | get(const tuple<_Types...>&& __t) noexcept | ^~~ /usr/include/c++/14/tuple:2505:5: note: 'template<class _Tp, class ... _Types> constexpr const _Tp& std::get(const tuple<_Elements ...>&)' 2505 | get(const tuple<_Types...>& __t) noexcept | ^~~ /usr/include/c++/14/tuple:2494:5: note: 'template<class _Tp, class ... _Types> constexpr _Tp&& std::get(tuple<_Elements ...>&&)' 2494 | get(tuple<_Types...>&& __t) noexcept | ^~~ /usr/include/c++/14/tuple:2483:5: note: 'template<class _Tp, class ... _Types> constexpr _Tp& std::get(tuple<_Elements ...>&)' 2483 | get(tuple<_Types...>& __t) noexcept | ^~~ /usr/include/c++/14/tuple:2476:5: note: 'template<long unsigned int __i, class ... _Elements> constexpr std::__enable_if_t<(__i >= sizeof... (_Types))> std::get(const tuple<_Elements ...>&)' 2476 | get(const tuple<_Elements...>&) = delete; | ^~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/bits/stl_pair.h:1307:5: note: 'template<class _Tp, class _Up> constexpr const _Tp&& std::get(const pair<_Up, _Tp>&&)' 1307 | get(const pair<_Up, _Tp>&& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1302:5: note: 'template<class _Tp, class _Up> constexpr _Tp&& std::get(pair<_Up, _Tp>&&)' 1302 | get(pair<_Up, _Tp>&& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1297:5: note: 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const pair<_Up, _Tp>&)' 1297 | get(const pair<_Up, _Tp>& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1292:5: note: 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_Up, _Tp>&)' 1292 | get(pair<_Up, _Tp>& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1287:5: note: 'template<class _Tp, class _Up> constexpr const _Tp&& std::get(const pair<_T1, _T2>&&)' 1287 | get(const pair<_Tp, _Up>&& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1282:5: note: 'template<class _Tp, class _Up> constexpr _Tp&& std::get(pair<_T1, _T2>&&)' 1282 | get(pair<_Tp, _Up>&& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1277:5: note: 'template<class _Tp, class _Up> constexpr const _Tp& std::get(const pair<_T1, _T2>&)' 1277 | get(const pair<_Tp, _Up>& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1272:5: note: 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_T1, _T2>&)' 1272 | get(pair<_Tp, _Up>& __p) noexcept | ^~~ In file included from /usr/include/c++/14/functional:65, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53: /usr/include/c++/14/array:417:5: note: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp&& std::get(const array<_Tp, _Nm>&&)' 417 | get(const array<_Tp, _Nm>&& __arr) noexcept | ^~~ /usr/include/c++/14/array:408:5: note: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const array<_Tp, _Nm>&)' 408 | get(const array<_Tp, _Nm>& __arr) noexcept | ^~~ /usr/include/c++/14/array:399:5: note: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(array<_Tp, _Nm>&&)' 399 | get(array<_Tp, _Nm>&& __arr) noexcept | ^~~ /usr/include/c++/14/array:390:5: note: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(array<_Tp, _Nm>&)' 390 | get(array<_Tp, _Nm>& __arr) noexcept | ^~~ /usr/include/c++/14/tuple:2466:5: note: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(const tuple<_Elements ...>&&)' 2466 | get(const tuple<_Elements...>&& __t) noexcept | ^~~ /usr/include/c++/14/tuple:2457:5: note: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(tuple<_Elements ...>&&)' 2457 | get(tuple<_Elements...>&& __t) noexcept | ^~~ /usr/include/c++/14/tuple:2451:5: note: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const tuple<_Elements ...>&)' 2451 | get(const tuple<_Elements...>& __t) noexcept | ^~~ /usr/include/c++/14/tuple:2445:5: note: 'template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(tuple<_Elements ...>&)' 2445 | get(tuple<_Elements...>& __t) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1265:5: note: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(const pair<_Tp1, _Tp2>&&)' 1265 | get(const pair<_Tp1, _Tp2>&& __in) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1260:5: note: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const pair<_Tp1, _Tp2>&)' 1260 | get(const pair<_Tp1, _Tp2>& __in) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1255:5: note: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(pair<_Tp1, _Tp2>&&)' 1255 | get(pair<_Tp1, _Tp2>&& __in) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1250:5: note: 'template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(pair<_Tp1, _Tp2>&)' 1250 | get(pair<_Tp1, _Tp2>& __in) noexcept | ^~~ a.cc:4:32: note: 'int get [8010]' 4 | int first[MAXN*2],next[MAXN*2],get[MAXN*2],have1,have2; | ^~~ a.cc:7:43: error: reference to 'next' is ambiguous 7 | inline void add(int x,int y){get[++top]=y;next[top]=first[x];first[x]=top;} | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:4:19: note: 'int next [8010]' 4 | int first[MAXN*2],next[MAXN*2],get[MAXN*2],have1,have2; | ^~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:10:33: error: reference to 'next' is ambiguous 10 | for (int i=first[x];i;i=next[i]){ | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter
s007963003
p04049
C++
#include<bits/stdc++.h> #define LF double #define LL long long #define ULL unsigned int #define fo(i,j,k) for(int i=j;i<=k;i++) #define fd(i,j,k) for(int i=j;i>=k;i--) #define fr(i,j) for(int i=begin[j];i;i=nxt[i]) using namespace std; int const mn=2*1e3+3,mo=1e9+7; int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],nxt[mn*2]; void insert(int u,int v){ to[++gra]=v; nxt[gra]=begin[u]; begin[u]=gra; } void dfs(int p,int q,int dep){ tmp++; if(!dep)return; fr(i,p)if(to[i]!=q) dfs(to[i],p,dep-1); } int main(){ scanf("%d%d",&n,&K); fo(i,1,n-1){ scanf("%d%d",&u[i],&v[i]); insert(u[i],v[i]); insert(v[i],u[i]); } int ans=0; if(K&1){ fo(i,1,n-1){ tmp=0; dfs(u[i],v[i],K/2); dfs(v[i],u[i],K/2); ans=max(ans,tmp); } }else{ fo(i,1,n){ tmp=0; dfs(i,0,K/2); ans=max(ans,tmp); } } printf("%d",n-ans); return 0; }
a.cc: In function 'void insert(int, int)': a.cc:13:14: error: reference to 'begin' is ambiguous 13 | nxt[gra]=begin[u]; | ^~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166, from a.cc:1: /usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)' 1238 | begin(const valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/valarray:1227:5: note: 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)' 1227 | begin(valarray<_Tp>& __va) noexcept | ^~~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52: /usr/include/c++/14/bits/range_access.h:95:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])' 95 | begin(_Tp (&__arr)[_Nm]) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:63:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)' 63 | begin(const _Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/bits/range_access.h:52:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)' 52 | begin(_Container& __cont) -> decltype(__cont.begin()) | ^~~~~ In file included from /usr/include/c++/14/bits/algorithmfwd.h:39, from /usr/include/c++/14/bits/stl_algo.h:59, from /usr/include/c++/14/algorithm:61, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/initializer_list:88:5: note: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:10:29: note: 'int begin [2003]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],nxt[mn*2]; | ^~~~~ a.cc:14:5: error: reference to 'begin' is ambiguous 14 | begin[u]=gra; | ^~~~~ /usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)' 1238 | begin(const valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/valarray:1227:5: note: 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)' 1227 | begin(valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:95:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])' 95 | begin(_Tp (&__arr)[_Nm]) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:63:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)' 63 | begin(const _Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/bits/range_access.h:52:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)' 52 | begin(_Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/initializer_list:88:5: note: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:10:29: note: 'int begin [2003]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],nxt[mn*2]; | ^~~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:7:27: error: reference to 'begin' is ambiguous 7 | #define fr(i,j) for(int i=begin[j];i;i=nxt[i]) | ^~~~~ a.cc:19:5: note: in expansion of macro 'fr' 19 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)' 1238 | begin(const valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/valarray:1227:5: note: 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)' 1227 | begin(valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:95:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])' 95 | begin(_Tp (&__arr)[_Nm]) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:63:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)' 63 | begin(const _Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/bits/range_access.h:52:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)' 52 | begin(_Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/initializer_list:88:5: note: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:10:29: note: 'int begin [2003]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],nxt[mn*2]; | ^~~~~
s438260426
p04049
C++
#include<bits/stdc++.h> #define LF double #define LL long long #define ULL unsigned int #define fo(i,j,k) for(int i=j;i<=k;i++) #define fd(i,j,k) for(int i=j;i>=k;i--) #define fr(i,j) for(int i=begin[j];i;i=next[i]) using namespace std; int const mn=2*1e3+3,mo=1e9+7; int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; void insert(int u,int v){ to[++gra]=v; next[gra]=begin[u]; begin[u]=gra; } void dfs(int p,int q,int dep){ tmp++; if(!dep)return; fr(i,p)if(to[i]!=q) dfs(to[i],p,dep-1); } int main(){ scanf("%d%d",&n,&K); fo(i,1,n-1){ scanf("%d%d",&u[i],&v[i]); insert(u[i],v[i]); insert(v[i],u[i]); } int ans=0; if(K&1){ fo(i,1,n-1){ tmp=0; dfs(u[i],v[i],K/2); dfs(v[i],u[i],K/2); ans=max(ans,tmp); } }else{ fo(i,1,n){ tmp=0; dfs(i,0,K/2); ans=max(ans,tmp); } } printf("%d",n-ans); return 0; }
a.cc: In function 'void insert(int, int)': a.cc:13:5: error: reference to 'next' is ambiguous 13 | next[gra]=begin[u]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:10:48: note: 'int next [4006]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~ a.cc:13:15: error: reference to 'begin' is ambiguous 13 | next[gra]=begin[u]; | ^~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166: /usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)' 1238 | begin(const valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/valarray:1227:5: note: 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)' 1227 | begin(valarray<_Tp>& __va) noexcept | ^~~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52: /usr/include/c++/14/bits/range_access.h:95:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])' 95 | begin(_Tp (&__arr)[_Nm]) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:63:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)' 63 | begin(const _Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/bits/range_access.h:52:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)' 52 | begin(_Container& __cont) -> decltype(__cont.begin()) | ^~~~~ In file included from /usr/include/c++/14/bits/algorithmfwd.h:39, from /usr/include/c++/14/bits/stl_algo.h:59, from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/initializer_list:88:5: note: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:10:29: note: 'int begin [2003]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:14:5: error: reference to 'begin' is ambiguous 14 | begin[u]=gra; | ^~~~~ /usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)' 1238 | begin(const valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/valarray:1227:5: note: 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)' 1227 | begin(valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:95:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])' 95 | begin(_Tp (&__arr)[_Nm]) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:63:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)' 63 | begin(const _Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/bits/range_access.h:52:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)' 52 | begin(_Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/initializer_list:88:5: note: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:10:29: note: 'int begin [2003]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:7:27: error: reference to 'begin' is ambiguous 7 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~~ a.cc:19:5: note: in expansion of macro 'fr' 19 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/valarray:1238:5: note: candidates are: 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)' 1238 | begin(const valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/valarray:1227:5: note: 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)' 1227 | begin(valarray<_Tp>& __va) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:95:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])' 95 | begin(_Tp (&__arr)[_Nm]) noexcept | ^~~~~ /usr/include/c++/14/bits/range_access.h:63:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)' 63 | begin(const _Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/bits/range_access.h:52:5: note: 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)' 52 | begin(_Container& __cont) -> decltype(__cont.begin()) | ^~~~~ /usr/include/c++/14/initializer_list:88:5: note: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:10:29: note: 'int begin [2003]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:7:40: error: reference to 'next' is ambiguous 7 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~ a.cc:19:5: note: in expansion of macro 'fr' 19 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:10:48: note: 'int next [4006]' 10 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~
s348969394
p04049
C++
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define LF double #define LL long long #define ULL unsigned int #define fo(i,j,k) for(int i=j;i<=k;i++) #define fd(i,j,k) for(int i=j;i>=k;i--) #define fr(i,j) for(int i=begin[j];i;i=next[i]) using namespace std; int const mn=2*1e3+3,mo=1e9+7; int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; void insert(int u,int v){ to[++gra]=v; next[gra]=begin[u]; begin[u]=gra; } void dfs(int p,int q,int dep){ tmp++; if(!dep)return; fr(i,p)if(to[i]!=q) dfs(to[i],p,dep-1); } int main(){ scanf("%d%d",&n,&K); fo(i,1,n-1){ scanf("%d%d",&u[i],&v[i]); insert(u[i],v[i]); insert(v[i],u[i]); } int ans=0; if(K&1){ fo(i,1,n-1){ tmp=0; dfs(u[i],v[i],K/2); dfs(v[i],u[i],K/2); ans=max(ans,tmp); } }else{ fo(i,1,n){ tmp=0; dfs(i,0,K/2); ans=max(ans,tmp); } } printf("%d",n-ans); return 0; }
a.cc: In function 'void insert(int, int)': a.cc:16:5: error: reference to 'next' is ambiguous 16 | next[gra]=begin[u]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/bits/specfun.h:43, from /usr/include/c++/14/cmath:3906, from a.cc:2: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:13:48: note: 'int next [4006]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~ a.cc:16:15: error: reference to 'begin' is ambiguous 16 | next[gra]=begin[u]; | ^~~~~ In file included from /usr/include/c++/14/bits/algorithmfwd.h:39, from /usr/include/c++/14/bits/stl_algo.h:59, from /usr/include/c++/14/algorithm:61, from a.cc:4: /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:17:5: error: reference to 'begin' is ambiguous 17 | begin[u]=gra; | ^~~~~ /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:10:27: error: reference to 'begin' is ambiguous 10 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~~ a.cc:22:5: note: in expansion of macro 'fr' 22 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:10:40: error: reference to 'next' is ambiguous 10 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~ a.cc:22:5: note: in expansion of macro 'fr' 22 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:13:48: note: 'int next [4006]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~
s609073562
p04049
C++
#include<cstdio> #include<vector> #include<algorithm> using namespace std; const int MAXN=2005; int n,k,Ans=MAXN; int son[MAXN],vis[MAXN]; vector<int>T[MAXN]; void Dfs(int u,int fa,int dep,int gra){ if(dep>k/2){ if(k%2)son[gra]++; return ; } vis[u]=1; int size=T[u].size(); for(int i=0;i<size;i++){ int v=T[u][i]; if(v==fa)continue; Dfs(v,u,dep+1,gra); } } int main(){ scanf("%d%d",&n,&k); for(int i=1;i<n;i++){ int x,y; scanf("%d%d",&x,&y); T[x].push_back(y); T[y].push_back(x); } for(int i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); memset(son,0,sizeof(son)); int size=T[i].size(),ret=0; vis[i]=1; for(int j=0;j<size;j++){ int v=T[i][j]; Dfs(v,i,1,v); ret=min(ret,-son[v]); } for(int j=1;j<=n;j++) if(!vis[j])ret++; if(ret<Ans)Ans=ret; } printf("%d\n",Ans); }
a.cc: In function 'int main()': a.cc:31:17: error: 'memset' was not declared in this scope 31 | memset(vis,0,sizeof(vis)); | ^~~~~~ a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 3 | #include<algorithm> +++ |+#include <cstring> 4 | using namespace std;
s407676720
p04049
C++
#include<bits/stdc++.h> using namespace std; const int N=2005; int head[N],ver[N*2],nxt[N*2],tot; int n,k; int dp[N]; int g[N]; void add(int x,int y) { ver[++tot]=y; nxt[tot]=head[x]; head[x]=tot; } void dfs(int rt,int fa,int dep) { for(int i=head[rt]; i; i=nxt[i]) { int y=ver[i]; if(y!=fa) { dfs(y,rt,dep+1); g[rt]+=g[y]+1; dp[rt]+=dp[y]; } } if(dep>k/2) dp[rt]=g[rt]; } int main() { scanf("%d%d",&n,&k); int x,y; for(int i=1; i<n; i++) { scanf("%d%d",&x,&y); add(x,y); add(y,x); } int ans=1e9; if(k%2==0) { for(int i=1; i<=n; i++) { memset(dp,0,sizeof(dp)); memset(g,0,sizeof(g)); dfs(i,i,1); ans=min(ans,dp[i]); //cout<<dp[i]<<endl; } } else { for(int x=1;x<=n;x++) { for(int i=head[x];i;i=nxt[i]) { memset(dp,0,sizeof(dp)); memset(g,0,sizeof(g)); int y=ver[i]; b[y]=1; dfs(x,y,1); dfs(y,x,1); ans=min(ans,dp[x]+dp[y]); } } } printf("%d",ans); return 0; }
a.cc: In function 'int main()': a.cc:60:33: error: 'b' was not declared in this scope 60 | b[y]=1; | ^
s279619983
p04049
C++
#include <bits/stdc++.h> using namespace std; const int maxn=2010; int n,k,tans,ans,x,y; bool vis[maxn]; vector <int> e[maxn]; priority_queue <int> Qmax; void dfs(int root,int node,int dep){ //cout<<node<<endl; Qmax.push(dep); vis[node]=1; for(int i=0;i<e[node].size();++i) if(!vis[e[node][i]])dfs(root,e[node][i],dep+1); } int main(){ scanf("%d%d",&n,&k); for(int i=1;i<n;++i){ scanf("%d%d",&x,&y); e[x].push_back(y); e[y].push_back(x); } ans=n-k-1; for(int i=1;i<=n;++i){ for(;!Qmax.empty();Qmax.pop()); if(e[i].size()<2)continue; tans=0; memset(vis,0,sizeof(vis)); vis[i]=1; for(int j=0;j<e[i].size();++j){ int t=e[i][j]; for(;!Q[t].empty();Q[t].pop()); dfs(t,t,1); Qmax.push(t); } int now=Qmax.top(); Qmax.pop(); int sec=Qmax.top(); for(;now+sec>k;++tans){ now=Qmax.top(); sec=Qmax.top(); } ans=min(ans,tans); } printf("%d\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:31:31: error: 'Q' was not declared in this scope 31 | for(;!Q[t].empty();Q[t].pop()); | ^
s276664750
p04049
C++
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <string> #define FI first #define SE second #define PF push_front #define PB push_back #define PPF pop_front #define PPB pop_back #define MA make_pair #define ll long long #define PA pair<int,int> #define VE vector<int> #define VP vector<PA> #define FOR(i,a,b) for(int i=a;i<b;i++) #define ROF(i,a,b) for(int i=b-1;i>=a;i--) #define YES(i) cout<<(i?"YES":"NO")<<endl #define Yes(i) cout<<(i?"Yes":"No")<<endl #define POSSIBLE(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl #define Possible(i) cout<<(i?"Possible":"Impossible")<<endl using namespace std; // const int INF=1e9+7; const int mod=998244353; // struct poi{ int X;int Y;int Z; bool operator<(const poi&R)const{ return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X; } }; // ll GCD(ll A,ll B){ return (B==0)?(A):(GCD(B,A%B)); } ll LCM(ll A,ll B){ return A/GCD(A,B)*B; } // int N,K; vector<int> V[2000]; int num[2000]; int m; void DFS(int n,int ran){ FOR(i,0,V[n].size()){ if(num[V[n][i]]==INF){ num[V[n][i]]=ran; if(ran==K/2){ if(ran*2+1==K){ m=max(m,(int)V[n][i].size()-1); } continue; }else{ DFS(V[n][i],ran+1); } } } } int main(){ cin>>N>>K; FOR(i,0,N-1){ int A,B; cin>>A>>B; A--;B--; V[A].PB(B); V[B].PB(A); } int ans=INF; FOR(i,0,N){ if(V[i].size()==1){ continue; } fill(num,num+N,INF); num[i]=0; m=0; DFS(i,1); sort(num,num+N); if(K%2==0){ ans=min(ans,N-(int)(upper_bound(num,num+N,K/2)-num)); }else{ ans=min(ans,N-(int)(upper_bound(num,num+N,K/2)-num)-m); } } cout<<ans<<endl; return 0; }
a.cc: In function 'void DFS(int, int)': a.cc:53:62: error: request for member 'size' in 'V[n].std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 53 | m=max(m,(int)V[n][i].size()-1); | ^~~~
s415676991
p04049
C++
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <cstdio> #include <string> #define FI first #define SE second #define PF push_front #define PB push_back #define PPF pop_front #define PPB pop_back #define MA make_pair #define ll long long #define PA pair<int,int> #define VE vector<int> #define VP vector<PA> #define FOR(i,a,b) for(int i=a;i<b;i++) #define ROF(i,a,b) for(int i=b-1;i>=a;i--) #define YES(i) cout<<(i?"YES":"NO")<<endl #define Yes(i) cout<<(i?"Yes":"No")<<endl #define POSSIBLE(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl #define Possible(i) cout<<(i?"Possible":"Impossible")<<endl using namespace std; // const int INF=1e9+7; const int mod=998244353; // struct poi{ int X;int Y;int Z; bool operator<(const poi&R)const{ return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X; } }; // ll GCD(ll A,ll B){ return (B==0)?(A):(GCD(B,A%B)); } ll LCM(ll A,ll B){ return A/GCD(A,B)*B; } // int N,K; vector<int> V[2000]; int num[2000]; int s; void DFS(int n,int ran){ if(ran>=K){ return; }else{ FOR(i,0,V[n].size()){ if(num[V[n][i]]>ran){ num[V[n][i]]=ran; DFS(V[n][i],ran+1); } } } } int main(){ cin>>N>>K; FOR(i,0,N-1){ int A,B; cin>>A>>B; A--;B--; V[A].PB(B); V[B].PB(A); } int ans=INF; FOR(i,0,N){ fill(num,num+N,INF); num[i]=0; DFS(i,1); ans=min(ans,N-(upper_bound(num,num+N,K)-num)); } cout<<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:74:24: error: no matching function for call to 'min(int&, long int)' 74 | ans=min(ans,N-(upper_bound(num,num+N,K)-num)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:74:24: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long int') 74 | ans=min(ans,N-(upper_bound(num,num+N,K)-num)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61, from a.cc:2: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:74:24: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 74 | ans=min(ans,N-(upper_bound(num,num+N,K)-num)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s904757657
p04049
C++
#include <iostream> #include <cmath> #include <algorithm> #include <vector> #define INF 1000000 #define MAX_V 2010 using namespace std; struct edge{int to,cost; }; vector<edge> G[MAX_V]; bool used[MAX_V]; bool c[MAX_V][MAX_V]; int d[MAX_V],h[MAX_V],f[MAX_V][MAX_V]; int V; void dfs(int s){ used[s] = true; int i = 0; while(true){ edge e = G[s][i]; if(e.to==-1){ break; } if(!used[e.to]){ i++; used[e.to] = true; d[e.to] = d[s] + e.cost; dfs(e.to); }else{ i++; } } } int main(){ int i,j,k,mx,l,ans=0; cin >> V >> k; for(i=0;i<V-1;i++){ int s,t; cin >> s >> t; s--; t--; edge e; e.to = t; e.cost = 1; G[s].push_back(e); e.to = s; e.cost = 1; G[t].push_back(e); } for(i=0;i<V;i++){ edge e; e.to = -1; e.cost = 0; G[i].push_back(e); } for(i=0;i<V;i++){ h[i] = 0; for(j=0;j<V;j++){ c[i][j] = 0; used[j] = false; } d[i] = 0; dfs(i); for(j=0;j<V;j++){ f[i][j] = d[j]; } } for(i=0;i<V;i++){ for(j=0;j<V;j++){ if(f[i][j]>k){ c[i][j] = false; h[i]++; h[j]++; } } } for(i=0;i<V;i++){ mx = 0; for(j=0;j<V;j++){ if(g[j]>mx){ mx = h[j]; l = j; } } if(mx==0){ break; } for(j=0;j<V;j++){ if(!c[j][l]){ c[j][l] = true; h[l]--; h[j]--; } if(!c[l][j]){ c[l][j] = true; h[l]--; h[j]--; } } ans++; } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:82:28: error: 'g' was not declared in this scope 82 | if(g[j]>mx){ | ^
s910221965
p04049
C++
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <math.h> using namespace std; const int MAXN = 2000 + 10; int N, K; vector<int> A[MAXN]; int ans; inline int Dfs( int x, int p, int t, int y ) { register int i; int res = 1; if(t != y) for( i = 0; i < (int) A[x].size(); ++i ) if(A[x][i] != p) res += Dfs(A[x][i], x, t + 1, y); return res; } int main() { register int i, j; int x, y; scanf( "%d%d", &N, &K ); for( i = 1; i < N; ++i ) scanf( "%d%d", &x, &y ), A[--x].push_back(--y), A[y].push_back(x); if(K & 1) for( i = 0; i < N; ++i ) for( j = 0; j < (int) A[i].size(); ++j ) ans = max( ans, Dfs( i, A[i][j], 0, K >> 1 ) + Dfs( A[i][j], i, 0, K >> 1 ) ); else for( i = 0; i < N; ++i ) ans = max( ans, Dfs( i, -1, 0, K >> 1 ) ); printf( "%d\n", N - ans ); return 0; }
a.cc:10:1: error: 'vector' does not name a type 10 | vector<int> A[MAXN]; | ^~~~~~ a.cc: In function 'int Dfs(int, int, int, int)': a.cc:14:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 14 | register int i; | ^ a.cc:17:39: error: 'A' was not declared in this scope 17 | for( i = 0; i < (int) A[x].size(); ++i ) | ^ a.cc: In function 'int main()': a.cc:24:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 24 | register int i, j; int x, y; | ^ a.cc:24:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 24 | register int i, j; int x, y; | ^ a.cc:28:17: error: 'A' was not declared in this scope 28 | A[--x].push_back(--y), A[y].push_back(x); | ^ a.cc:31:47: error: 'A' was not declared in this scope 31 | for( j = 0; j < (int) A[i].size(); ++j ) | ^
s487392396
p04049
C++
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <math.h> using namespace std; const int MAXN = 2000 + 10; int N, K; vector<int> A[MAXN]; int ans; inline int Dfs( int x, int p, int t, int y ) { register int i; int res = 1; if(t != y) for( i = 0; i < (int) A[x].size(); ++i ) if(A[i] != p) res += Dfs(A[i], x, t + 1, y); return res; } int main() { register int i, j; int x, y; scanf( "%d%d", &N, &K ); for( i = 1; i < N; ++i ) scanf( "%d%d", &x, &y ), A[--x].push_back(--y), A[y].push_back(x); if(K & 1) for( i = 0; i < N; ++i ) for( j = 0; j < (int) A[i].size(); ++j ) ans = max( ans, Dfs( i, A[j], 0, K >> 1 ) + Dfs( A[j], i, 0, K >> 1 ) ); else for( i = 0; i < N; ++i ) ans = max( ans, Dfs( i, -1, 0, K >> 1 ) ); printf( "%d\n", N - ans ); return 0; }
a.cc:10:1: error: 'vector' does not name a type 10 | vector<int> A[MAXN]; | ^~~~~~ a.cc: In function 'int Dfs(int, int, int, int)': a.cc:14:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 14 | register int i; | ^ a.cc:17:39: error: 'A' was not declared in this scope 17 | for( i = 0; i < (int) A[x].size(); ++i ) | ^ a.cc: In function 'int main()': a.cc:24:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 24 | register int i, j; int x, y; | ^ a.cc:24:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 24 | register int i, j; int x, y; | ^ a.cc:28:17: error: 'A' was not declared in this scope 28 | A[--x].push_back(--y), A[y].push_back(x); | ^ a.cc:31:47: error: 'A' was not declared in this scope 31 | for( j = 0; j < (int) A[i].size(); ++j ) | ^
s967882610
p04049
C++
#include <bits/stdc++.h> using namespace std; bool e[2000][2000]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; int a[n - 1], b[n - 1]; for (int i = 0; i < n - 1; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; e[a[i]][b[i]] = e[b[i]][a[i]] = 1; } long long res = 0; if (k % 2 == 0) { k /= 2; int v; int memo[n]; for (int i = 0; i < n; i++) { memset(memo, -1, sizeof(memo)); queue<int> q; memo[i] = 0, q.push(i); while (!q.empty()) { v = q.front(); q.pop(); for (int j = 0; j < n; j++) { if (e[v][j] and memo[j] == -1) { memo[j] = memo[v] + 1; q.push(j); } } } sort(memo, memo + n); res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); } } else { k /= 2; int v; int memo[n]; for (int i = 0; i < n - 1; i++) { memset(memo, -1, sizeof(memo)); queue<int> q; memo[a[i]] = memo[b[i]] = 0; q.push(a[i]); q.push(b[i]); while (!q.empty()) { v = q.front(); q.pop(); for (int j = 0; j < n; j++) { if (e[v][j] and memo[j] == -1) { memo[j] = memo[v] + 1; q.push(j); } } } sort(memo, memo + n); res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); } } cout << n - res << "\n"; return 0; }
a.cc: In function 'int main()': a.cc:32:16: error: no matching function for call to 'max(long long int&, long int)' 32 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:32:16: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int') 32 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:32:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 32 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:53:16: error: no matching function for call to 'max(long long int&, long int)' 53 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:53:16: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int') 53 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:53:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 53 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s898506426
p04049
C++
#include <bits/stdc++.h> using namespace std; bool e[2000][2000]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; int a[n - 1], b[n - 1]; for (int i = 0; i < n - 1; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; e[a[i]][b[i]] = e[b[i]][a[i]] = 1; } int res = 0; if (k % 2 == 0) { k /= 2; int v; int memo[n]; for (int i = 0; i < n; i++) { memset(memo, -1, sizeof(memo)); queue<int> q; memo[i] = 0, q.push(i); while (!q.empty()) { v = q.front(); q.pop(); for (int j = 0; j < n; j++) { if (e[v][j] and memo[j] == -1) { memo[j] = memo[v] + 1; q.push(j); } } } sort(memo, memo + n); res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); } } else { k /= 2; int v; int memo[n]; for (int i = 0; i < n - 1; i++) { memset(memo, -1, sizeof(memo)); queue<int> q; memo[a[i]] = memo[b[i]] = 0; q.push(a[i]); q.push(b[i]); while (!q.empty()) { v = q.front(); q.pop(); for (int j = 0; j < n; j++) { if (e[v][j] and memo[j] == -1) { memo[j] = memo[v] + 1; q.push(j); } } } sort(memo, memo + n); res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); } } cout << n - res << "\n"; return 0; }
a.cc: In function 'int main()': a.cc:32:16: error: no matching function for call to 'max(int&, long int)' 32 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:32:16: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long int') 32 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:32:16: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 32 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:53:16: error: no matching function for call to 'max(int&, long int)' 53 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:53:16: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long int') 53 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:53:16: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 53 | res = max(res, upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s962187660
p04049
C++
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define LF double #define LL long long #define ULL unsigned int #define fo(i,j,k) for(int i=j;i<=k;i++) #define fd(i,j,k) for(int i=j;i>=k;i--) #define fr(i,j) for(int i=begin[j];i;i=next[i]) using namespace std; int const mn=2*1e3+3,mo=1e9+7; int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; void insert(int u,int v){ to[++gra]=v; next[gra]=begin[u]; begin[u]=gra; } void dfs(int p,int q,int dep){ tmp++; if(!dep)return; fr(i,p)if(to[i]!=q) dfs(to[i],p,dep-1); } int main(){ scanf("%d%d",&n,&K); fo(i,1,n-1){ scanf("%d%d",&u[i],&v[i]); insert(u[i],v[i]); insert(v[i],u[i]); } int ans=0; if(K&1){ fo(i,1,n-1){ tmp=0; dfs(u[i],v[i],K/2); dfs(v[i],u[i],K/2); ans=max(ans,tmp); } }else{ fo(i,1,n){ tmp=0; dfs(i,0,K/2); ans=max(ans,tmp); } } printf("%d\n",n-ans); return 0; }
a.cc: In function 'void insert(int, int)': a.cc:16:5: error: reference to 'next' is ambiguous 16 | next[gra]=begin[u]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/bits/specfun.h:43, from /usr/include/c++/14/cmath:3906, from a.cc:2: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:13:48: note: 'int next [4006]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~ a.cc:16:15: error: reference to 'begin' is ambiguous 16 | next[gra]=begin[u]; | ^~~~~ In file included from /usr/include/c++/14/bits/algorithmfwd.h:39, from /usr/include/c++/14/bits/stl_algo.h:59, from /usr/include/c++/14/algorithm:61, from a.cc:4: /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:17:5: error: reference to 'begin' is ambiguous 17 | begin[u]=gra; | ^~~~~ /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:10:27: error: reference to 'begin' is ambiguous 10 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~~ a.cc:22:5: note: in expansion of macro 'fr' 22 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:10:40: error: reference to 'next' is ambiguous 10 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~ a.cc:22:5: note: in expansion of macro 'fr' 22 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:13:48: note: 'int next [4006]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~
s220446351
p04049
C++
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #define LF double #define LL long long #define ULL unsigned int #define fo(i,j,k) for(int i=j;i<=k;i++) #define fd(i,j,k) for(int i=j;i>=k;i--) #define fr(i,j) for(int i=begin[j];i;i=next[i]) using namespace std; int const mn=2*1e3+3,mo=1e9+7; int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; void insert(int u,int v){ to[++gra]=v; next[gra]=begin[u]; begin[u]=gra; } void dfs(int p,int q,int dep){ tmp++; if(!dep)return; fr(i,p)if(to[i]!=q) dfs(to[i],p,dep-1); } int main(){ freopen("c.in","r",stdin); freopen("c.out","w",stdout); scanf("%d%d",&n,&K); fo(i,1,n-1){ scanf("%d%d",&u[i],&v[i]); insert(u[i],v[i]); insert(v[i],u[i]); } int ans=0; if(K&1){ fo(i,1,n-1){ tmp=0; dfs(u[i],v[i],K/2); dfs(v[i],u[i],K/2); ans=max(ans,tmp); } }else{ fo(i,1,n){ tmp=0; dfs(i,0,K/2); ans=max(ans,tmp); } } printf("%d\n",n-ans); return 0; }
a.cc: In function 'void insert(int, int)': a.cc:16:5: error: reference to 'next' is ambiguous 16 | next[gra]=begin[u]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/bits/specfun.h:43, from /usr/include/c++/14/cmath:3906, from a.cc:2: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:13:48: note: 'int next [4006]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~ a.cc:16:15: error: reference to 'begin' is ambiguous 16 | next[gra]=begin[u]; | ^~~~~ In file included from /usr/include/c++/14/bits/algorithmfwd.h:39, from /usr/include/c++/14/bits/stl_algo.h:59, from /usr/include/c++/14/algorithm:61, from a.cc:4: /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:17:5: error: reference to 'begin' is ambiguous 17 | begin[u]=gra; | ^~~~~ /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:10:27: error: reference to 'begin' is ambiguous 10 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~~ a.cc:22:5: note: in expansion of macro 'fr' 22 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/initializer_list:88:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)' 88 | begin(initializer_list<_Tp> __ils) noexcept | ^~~~~ a.cc:13:29: note: 'int begin [2003]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~~ a.cc:10:40: error: reference to 'next' is ambiguous 10 | #define fr(i,j) for(int i=begin[j];i;i=next[i]) | ^~~~ a.cc:22:5: note: in expansion of macro 'fr' 22 | fr(i,p)if(to[i]!=q) | ^~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:13:48: note: 'int next [4006]' 13 | int n,K,tmp,u[mn],v[mn],gra,begin[mn],to[mn*2],next[mn*2]; | ^~~~
s562891551
p04049
C++
// see https://github.com/LumaKernel/vimfiles/tree/master/snippets/cp-cpp/temp.snip /// --- .lumrc Template {{{ /// // #define DEBUG // #define assert(...) #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using P = tuple<ll, ll>; using P3 = tuple<ll, ll, ll>; using VI = vector<int>; using VL = vector<ll>; using VVI = vector<VI>; using VVL = vector<VL>; using VP = vector<P>; using VS = vector<string>; #define omajinai ios::sync_with_stdio(false),cin.tie(0) #define FOR(i,a,b) for(int i=int(a);i<int(b);++i) #define FORI(i,a,b) for(int i=int(a);i<=int(b);++i) #define REP(i,n) FOR(i,0,n) #define REPI(i,n) FORI(i,0,n) #define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i) #define RFORI(i,a,b) for(int i=int(b);i>=int(a);--i) #define RREP(i,n) RFOR(i,0,n) #define RREPI(i,n) RFORI(i,0,n) #define ALL(a) begin(a),end(a) #define UNIQUE(a) (a).erase(unique(ALL(a)),(a).end()) #define PB push_back #define EACH(i,c) REP(i,(c).size()) #define REACH(i,c) RREP(i,(c).size()) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort(ALL(c)) #define BR cout<<"\n"; #ifdef DEBUG #define dump(...) cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n"; #else #define dump(...) #endif #define YES(x) cout<<((x)?"YES":"NO")<<"\n"; #define Yes(x) cout<<((x)?"Yes":"No")<<"\n"; #define yes(x) cout<<((x)?"yes":"no")<<"\n"; int __int_temp; ll __ll_temp; string __string_temp; #define oini (omajinai, cin>>__int_temp, __int_temp) #define oinl (omajinai, cin>>__ll_temp, __ll_temp) #define oins (omajinai, cin>>__string_temp, __string_temp) #define ini (cin>>__int_temp, __int_temp) #define inl (cin>>__ll_temp, __ll_temp) #define ins (cin>>__string_temp, __string_temp) #define isInside(y,x) (0<=(y)&&(y)<h&&0<=(x)&&(x)<w) #define fi(x) (get<0>(x)) #define se(x) (get<1>(x)) #define th(x) (get<2>(x)) #define fo(x) (get<3>(x)) #define fif(x) (get<4>(x)) template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '{'; EACH(i, v) o << v[i] << (i != (int)v.size()-1 ? ", " : ""); o << "}"; return o; } template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){} template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); } template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; } template <typename T> inline void smax(T &a, T b) { a = a > b ? a : b; } template <typename T> inline void smin(T &a, T b) { a = a < b ? a : b; } template<typename T> inline int intlog2(T x); template<> inline int intlog2(int x) { return x == 0 ? 0 : 32 - __builtin_clz(x); } template<> inline int intlog2(ll x) { return x == 0 ? 0 : 64 - __builtin_clzll(x); } constexpr double PI = acos(-1); /// }}}--- /// constexpr int INF = 1e9+1; constexpr ll LINF = 1e18+1; constexpr int MOD = 1e9+7; const int N = 2001; VI g[N]; int dist[2][N]; int size[2][N]; void dfs(int x, int i, int p = -1, int d = 0) { dist[x][i] = d; for(int j : g[i]) if(j != p) dfs(x, j, i, d+1); } int dfs2(int x, int i, int p = -1) { int c = 1; for(int j : g[i]) if(j != p) { c += dfs2(x, j, i); } return size[x][i] = c; } int n=ini, k=ini; VP treeone; bool dfs3(int i, int to, int p = -1) { if(i == to) { treeone.emplace_back(size[0][i], size[1][i]); return 1; } bool ecasdqina = 0; for(int j : g[i]) if(p != j) { ecasdqina |= dfs3(j, to, i); } if(ecasdqina) { treeone.emplace_back(size[0][i], size[1][i]); } return ecasdqina; } int main() { REP(i, n-1) { int a=ini-1,b=ini-1; g[a].PB(b); g[b].PB(a); } dfs(0, 0); int noel = 0; REP(i, n) if(dist[0][noel] < dist[0][i]) noel = i; dfs(1, dist[0][noel]); int taplis = 0; REP(i, n) if(dist[1][taplis] < dist[1][i]) taplis = i; dfs2(0, noel); dfs2(1, taplis); dfs3(noel, taplis); ll ans = LINF; dump(treeone); for(int i=0; i + k < (int) treeone.size(); i++) { int j = i + k; ll tmp = 0; tmp += fi(treeone[i]) - 1; tmp += se(treeone[j]) - 1; smin(ans, tmp); } if(ans == LINF) ans = 0;
a.cc: In function 'int dfs2(int, int, int)': a.cc:105:10: error: reference to 'size' is ambiguous 105 | return size[x][i] = c; | ^~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52, from a.cc:5: /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:92:5: note: 'int size [2][2001]' 92 | int size[2][N]; | ^~~~ a.cc: In function 'bool dfs3(int, int, int)': a.cc:113:26: error: reference to 'size' is ambiguous 113 | treeone.emplace_back(size[0][i], size[1][i]); | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:92:5: note: 'int size [2][2001]' 92 | int size[2][N]; | ^~~~ a.cc:113:38: error: reference to 'size' is ambiguous 113 | treeone.emplace_back(size[0][i], size[1][i]); | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:92:5: note: 'int size [2][2001]' 92 | int size[2][N]; | ^~~~ a.cc:121:26: error: reference to 'size' is ambiguous 121 | treeone.emplace_back(size[0][i], size[1][i]); | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:92:5: note: 'int size [2][2001]' 92 | int size[2][N]; | ^~~~ a.cc:121:38: error: reference to 'size' is ambiguous 121 | treeone.emplace_back(size[0][i], size[1][i]); | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:92:5: note: 'int size [2][2001]' 92 | int size[2][N]; | ^~~~ a.cc: In function 'int main()': a.cc:153:27: error: expected '}' at end of input 153 | if(ans == LINF) ans = 0; | ^ a.cc:126:12: note: to match this '{' 126 | int main() { | ^
s075651706
p04049
C++
#include<iostream> #include<cstdio> #define MN 2000 using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,K,head[MN+5],f[MN+5][MN+5],cnt,ans,F[MN+5]; struct edge{int to,next;}e[MN*2+5]; inline void ins(int f,int t) { e[++cnt]=(edge){t,head[f]};head[f]=cnt; e[++cnt]=(edge){f,head[t]};head[t]=cnt; } void Solve(int x,int fa) { for(int i=0;i<=K;++i) f[x][i]=1; for(int i=head[x];i;i=e[i].next) if(e[i].to!=fa) { Solve(e[i].to,x); memset(F,200,sizeof(F)); for(int j=1;j<=K;++j) F[j]=max(f[e[i].to][j-1]+f[x][min(K-j,j)],j<K?(f[x][j]+f[e[i].to][min(K-j-1,j-1)]):0); for(int j=1;j<=K;++j) f[x][j]=max(F[j],f[x][j-1]); } ans=max(ans,f[x][K]); //for(int j=0;j<=K;++j) printf("f[%d][%d]=%d\n",x,j,f[x][j]); } int main() { memset(f,200,sizeof(f)); n=read();K=read(); for(int i=1;i<n;++i) ins(read(),read()); Solve(1,0); printf("%d\n",n-ans); return 0; }
a.cc: In function 'void Solve(int, int)': a.cc:26:13: error: 'memset' was not declared in this scope 26 | memset(F,200,sizeof(F)); | ^~~~~~ a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 2 | #include<cstdio> +++ |+#include <cstring> 3 | #define MN 2000 a.cc: In function 'int main()': a.cc:36:5: error: 'memset' was not declared in this scope 36 | memset(f,200,sizeof(f)); | ^~~~~~ a.cc:36:5: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
s557965296
p04049
C++
#include <cstdio> #include <cstring> #include <ctime> #include <cstdlib> #include <cmath> #include <iostream> #include <string> #include <queue> #include <map> #include <stack> #include <vector> #include <algorithm> #include <set> #include <deque> #include <utility> #include <chrono> #include <sstream> #include <iomanip> #include <cassert> #define INF 1 << 30 #define MOD 1000000007; #define PI 3.14159265358979 #define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++) #define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++) #define D(x) cout << x << endl #define d(x) cout << x #define all(x) (x).begin(), (x).end() #define pub(x) push_back(x) #define pob() pop_back() #define puf(x) push_front(x) #define pof() pop_front() #define mp(x, y) make_pair((x), (y)) #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<double> vd; typedef vector<long long> vll; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> pii; typedef pair<long, long> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } static const int dx[] = {0, 0, 1, -1}; static const int dy[] = {-1, 1, 0, 0}; int n, k; vector<vi> e(2020); int dfs(int x, int p, int d) { int ans = 1; if (d < k / 2) { for (int y : e[x]) { if (y == p) { continue; } ans += dfs(y, x, d + 1); } } return ans; } vector<int> Centroid(int root, const vector<vector<int>> &g, const vector<bool> &dead) { static vector<int> sz(g.size()); int alive_cnt = 0; function<void (int, int)> count_alive = [&](int u, int prev) { alive_cnt ++; for (auto v : g[u]) if (v != prev && !dead[v]) { count_alive(v, u); } }; count_alive(root, -1); vector<int> centroid; function<void (int, int)> dfs = [&](int u, int prev) { sz[u] = 1; bool is_centroid = true; for (auto v : g[u]) if (v != prev && !dead[v]) { dfs(v, u); sz[u] += sz[v]; if (sz[v] > alive_cnt / 2) is_centroid = false; } if (alive_cnt - sz[u] > alive_cnt / 2) is_centroid = false; if (is_centroid) centroid.push_back(u); }; dfs(root, -1); return centroid; } int OneCentroid(int root, const vector<vector<int>> &g, const vector<bool> &dead) { static vector<int> sz(g.size()); //caution function<void (int, int)> get_sz = [&](int u, int prev) { sz[u] = 1; for (auto v : g[u]) if (v != prev && !dead[v]) { get_sz(v, u); sz[u] += sz[v]; } }; get_sz(root, -1); int n = sz[root]; function<int (int, int)> dfs = [&](int u, int prev) { for (auto v : g[u]) if (v != prev && !dead[v]) { if (sz[v] > n / 2) { return dfs(v, u); } } return u; }; return dfs(root, -1); } int main() { cin >> n >> k; vector<vector<int>> g(n); rep(i, n - 1) { int a, b; cin >> a >> b, -- a, -- b; e[a].pub(b); e[b].pub(a); g[a].push_back(b); g[b].push_back(a); } vector<bool> dead(n); vector<int> centroids = Centroid(0, g, dead); int c = OneCentroid(0, g, dead); assert(c == centroids[0] || c == centroids[1]); int ans = 0; if (k & 1) { rep(i, n) { for (int j : e[i]) { amax(ans, dfs(i, j, 0) + dfs(j, i, 0)); } } } else { rep(i, n) { amax(ans, dfs(i, -1, 0)); } } D(n - ans); return 0; }
a.cc: In function 'std::vector<int> Centroid(int, const std::vector<std::vector<int> >&, const std::vector<bool>&)': a.cc:74:9: error: 'function' was not declared in this scope 74 | function<void (int, int)> count_alive = [&](int u, int prev) { | ^~~~~~~~ a.cc:20:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>' 19 | #include <cassert> +++ |+#include <functional> 20 | a.cc:74:32: error: expression list treated as compound expression in functional cast [-fpermissive] 74 | function<void (int, int)> count_alive = [&](int u, int prev) { | ^ a.cc:74:18: error: expected primary-expression before 'void' 74 | function<void (int, int)> count_alive = [&](int u, int prev) { | ^~~~ a.cc:80:9: error: 'count_alive' was not declared in this scope 80 | count_alive(root, -1); | ^~~~~~~~~~~ a.cc:82:32: error: expression list treated as compound expression in functional cast [-fpermissive] 82 | function<void (int, int)> dfs = [&](int u, int prev) { | ^ a.cc:82:18: error: expected primary-expression before 'void' 82 | function<void (int, int)> dfs = [&](int u, int prev) { | ^~~~ a.cc:93:12: error: too few arguments to function 'int dfs(int, int, int)' 93 | dfs(root, -1); | ~~~^~~~~~~~~~ a.cc:58:5: note: declared here 58 | int dfs(int x, int p, int d) { | ^~~ a.cc: In function 'int OneCentroid(int, const std::vector<std::vector<int> >&, const std::vector<bool>&)': a.cc:99:9: error: 'function' was not declared in this scope 99 | function<void (int, int)> get_sz = [&](int u, int prev) { | ^~~~~~~~ a.cc:99:9: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>' a.cc:99:32: error: expression list treated as compound expression in functional cast [-fpermissive] 99 | function<void (int, int)> get_sz = [&](int u, int prev) { | ^ a.cc:99:18: error: expected primary-expression before 'void' 99 | function<void (int, int)> get_sz = [&](int u, int prev) { | ^~~~ a.cc:106:9: error: 'get_sz' was not declared in this scope 106 | get_sz(root, -1); | ^~~~~~ a.cc:108:31: error: expression list treated as compound expression in functional cast [-fpermissive] 108 | function<int (int, int)> dfs = [&](int u, int prev) { | ^ a.cc:108:18: error: expected primary-expression before 'int' 108 | function<int (int, int)> dfs = [&](int u, int prev) { | ^~~ a.cc:116:19: error: too few arguments to function 'int dfs(int, int, int)' 116 | return dfs(root, -1); | ~~~^~~~~~~~~~ a.cc:58:5: note: declared here 58 | int dfs(int x, int p, int d) { | ^~~
s889236260
p04049
C++
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; // template from zscoder int n,k,visited[2001]; vi a(2001); vi b(2001); vi g(2001); int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); cin >> n >> k; for(int i = 0; i < n; i++) { cin >> a[i] >> b[i]; g[a[i]].pb(b[i]); g[b[i]].pb(a[i]); } int cur = 0; if(k%2==0) { for(int i = 1; i <= n; i++) { visited[i]=1; stack< ii >X; X.push(mp(i,0)); while(!X.empty()) { ii Y = X.top(); X.pop(); if(Y.se>(K/2))cur++; for(int j = 0; j < g[Y.fi].size(); j++) { if(visited[g[Y.fi][j]]==0) { X.push(mp(g[Y.fi][j],Y.se+1)); visited[g[Y.fi][j]] = 1; } } } } } else { for(int i = 1; i <= n; i++) { visited[a[i]]=1; visited[b[i]]=1; stack< ii >X; X.push(mp(a[i],0)); X.push(mp(b[i],0)); while(!X.empty()) { ii Y = X.top(); X.pop(); if(Y.se>(K-1/2))cur++; for(int j = 0; j < g[Y.fi].size(); j++) { if(visited[g[Y.fi][j]]==0) { X.push(mp(g[Y.fi][j],Y.se+1)); visited[g[Y.fi][j]] = 1; } } } } } cout << cur << endl; }
a.cc: In function 'int main()': a.cc:11:12: error: request for member 'push_back' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)a.std::vector<int>::operator[](((std::vector<int>::size_type)i))))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 11 | #define pb push_back | ^~~~~~~~~ a.cc:39:17: note: in expansion of macro 'pb' 39 | g[a[i]].pb(b[i]); | ^~ a.cc:11:12: error: request for member 'push_back' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)b.std::vector<int>::operator[](((std::vector<int>::size_type)i))))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 11 | #define pb push_back | ^~~~~~~~~ a.cc:40:17: note: in expansion of macro 'pb' 40 | g[b[i]].pb(a[i]); | ^~ a.cc:54:26: error: 'K' was not declared in this scope 54 | if(Y.se>(K/2))cur++; | ^ a.cc:55:44: error: request for member 'size' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)Y.std::pair<int, int>::first))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 55 | for(int j = 0; j < g[Y.fi].size(); j++) | ^~~~ a.cc:57:39: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript 57 | if(visited[g[Y.fi][j]]==0) | ^ a.cc:59:42: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript 59 | X.push(mp(g[Y.fi][j],Y.se+1)); | ^ a.cc:60:40: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript 60 | visited[g[Y.fi][j]] = 1; | ^ a.cc:79:26: error: 'K' was not declared in this scope 79 | if(Y.se>(K-1/2))cur++; | ^ a.cc:80:44: error: request for member 'size' in 'g.std::vector<int>::operator[](((std::vector<int>::size_type)Y.std::pair<int, int>::first))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 80 | for(int j = 0; j < g[Y.fi].size(); j++) | ^~~~ a.cc:82:39: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript 82 | if(visited[g[Y.fi][j]]==0) | ^ a.cc:84:42: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript 84 | X.push(mp(g[Y.fi][j],Y.se+1)); | ^ a.cc:85:40: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[int]' for array subscript 85 | visited[g[Y.fi][j]] = 1; | ^
s549326952
p04049
C++
#define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<vector> #include<string> #include<iostream> #include<algorithm> #include<map> #include<iterator> #include<set> #include<stack> #include<queue> #include<fstream> #include<iomanip> #include <unordered_map> #include <unordered_set> #include <numeric> #include<cmath> #include<list> #include <sstream> #include<unordered_map> using namespace std; #define FOR(i,a,b) for(int i = (a); i < (b); i++) #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--) #define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define ALL(a) a.begin(),a.end() #define SZ(a) (int)a.size() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 2000 + 47; int U[MAX]; vector<int> g[MAX]; int n, k; int cnt = 0; void fill(int A[], int val) { FOR(i, 0, MAX) A[i] = val; } void dfs(int v, int d) { if (d > k / 2) return; //cout << "*" << v + 1 << ": " << d << endl; cnt++; U[v] = 1; FOR(i, 0, SZ(g[v])) { int to = g[v][i]; if (!U[to]) dfs(to, d + 1); } } int calc(int i) { fill(U, 0); cnt = 0; dfs(i, 0); //cout << "?? " << i + 1 << " " << cnt << endl; int maxx = 0; int ind = -1; if (k % 2) { FOR(j, 0, n) { if (U[j]) { int c = 0; FOR(k, 0, SZ(g[j])) { if (!U[g[j][k]]) { c++; } } if (maxx < c) { maxx = c; ind = j; } } } FOR(i, 0, SZ(g[ind])) U[g[ind][i]] = 1; } return cnt + maxx; } int D[MAX]; void dfs1(int v, int p, int d) { D[v] = d; FOR(i, 0, SZ(g[v])) { int to = g[v][i]; if (U[to] && D[to] == -1) dfs1(to, v, d + 1); } } bool check(int v) { fill(D, -1); dfs1(v, -1, 0); int maxx = v; FOR(i, 0, n) { if (D[i] > D[maxx]) maxx = i; } FILL(D, -1); dfs1(maxx, -1, 0); FOR(i, 0, n) { if (D[i] > D[maxx]) maxx = i; } if (D[maxx] <= k) return true; return false; } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; FOR(i, 0, n - 1) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } if (k == 1) { cout << n - 2 << endl; return 0; } int ans = INF; int ind = -1; FOR(i, 0, n) { int cnt = calc(i); if (ans > n - cnt) { ans = n - cnt; ind = i; } } calc(ind); if (!check(ind)) { //cout << "-------------" << endl; throw - 1; } cout << ans << endl; }
a.cc: In function 'bool check(int)': a.cc:26:23: error: 'memset' was not declared in this scope 26 | #define FILL(a,value) memset(a, value, sizeof(a)) | ^~~~~~ a.cc:126:9: note: in expansion of macro 'FILL' 126 | FILL(D, -1); | ^~~~ a.cc:19:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 18 | #include<list> +++ |+#include <cstring> 19 | #include <sstream>
s015269939
p04049
C++
#define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<vector> #include<string> #include<iostream> #include<algorithm> #include<map> #include<iterator> #include<set> #include<stack> #include<queue> #include<fstream> #include<iomanip> #include <unordered_map> #include <unordered_set> #include <numeric> #include<cmath> #include<list> #include <sstream> #include<unordered_map> using namespace std; #define FOR(i,a,b) for(int i = (a); i < (b); i++) #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--) #define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define ALL(a) a.begin(),a.end() #define SZ(a) (int)a.size() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 2000 + 47; int U[MAX]; vector<int> g[MAX]; vector<int> V1, V2, V; int n, k; int cnt = 0; void dfs(int v, int d) { if (d > k / 2) return; //cout << "*" << v + 1 << ": " << d << endl; cnt++; U[v] = 1; FOR(i, 0, SZ(g[v])) { int to = g[v][i]; if (!U[to]) dfs(to, d + 1); } } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; FOR(i, 0, n - 1) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } int ans = INF; if (k % 2 == 0) { FOR(i, 0, n) { FILL(U, 0); cnt = 0; dfs(i, 0); //cout << "?? " << i + 1 << " " << cnt << endl; ans = min(ans, n - cnt); } cout << ans << endl; return 0; } FOR(i, 0, n) { FILL(U, 0); cnt = 0; dfs(i, 0); //cout << "?? " << i + 1 << " " << cnt << endl; int maxx = 0; FOR(j, 0, n) { int c = 0; if (U[j]) { FOR(k, 0, SZ(g[j])) { if (!U[g[j][k]]) c++; } } maxx = max(maxx, c); } ans = min(ans, n - cnt - maxx); } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:26:23: error: 'memset' was not declared in this scope 26 | #define FILL(a,value) memset(a, value, sizeof(a)) | ^~~~~~ a.cc:83:25: note: in expansion of macro 'FILL' 83 | FILL(U, 0); | ^~~~ a.cc:19:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 18 | #include<list> +++ |+#include <cstring> 19 | #include <sstream> a.cc:26:23: error: 'memset' was not declared in this scope 26 | #define FILL(a,value) memset(a, value, sizeof(a)) | ^~~~~~ a.cc:96:17: note: in expansion of macro 'FILL' 96 | FILL(U, 0); | ^~~~ a.cc:26:23: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 26 | #define FILL(a,value) memset(a, value, sizeof(a)) | ^~~~~~ a.cc:96:17: note: in expansion of macro 'FILL' 96 | FILL(U, 0); | ^~~~
s053949444
p04049
C++
#include<bits/stdc++.h> using namespace std; int n, k; vector<int> edge[2002]; int ans = 2147483647; int search(int now, int dis, int last) { int ans = 0; if (dis < 0) ans ++; for (int i = 0; i < edge[now].size(); i ++) if (edge[now][i] != last) { ans += search(edge[now][i], dis - 1, now); } return ans; } int main() { scanf("%d %d", &n, &k); for (int i = 1; i < n; i ++) { int x, y; scanf("%d %d", &x, &y); edge[x].push_back(y); edge[y].push_back(x); } if (k & 1) //for (int i = 1; i <= n; i ++) ans = min(ans, search(i, (k - 1) / 2, 0)); else for (int i = 1; i <= n; i ++) ans = min(ans, search(i, k / 2, 0)); printf("%d", ans); return 0; }
a.cc: In function 'int main()': a.cc:24:5: error: expected primary-expression before 'else' 24 | else | ^~~~ a.cc:25:25: error: 'i' was not declared in this scope 25 | for (int i = 1; i <= n; i ++) ans = min(ans, search(i, k / 2, 0)); | ^
s119662346
p04049
C++
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; int n,k,w[N],head[N],next[N]; void add(int f,int t){ static int cnt=0; w[++cnt]=t; next[cnt]=head[f]; head[f]=cnt; } int ans,cnt,dep[N],num[N]; void dfs(int x,int fa){ if (dep[x]<=k/2) cnt++; num[x]=0; if (dep[x]==k/2+1) num[x]++; for (int i=head[x];i;i=next[i]){ int v=w[i]; if (v==fa) continue; dep[v]=dep[x]+1; dfs(v,x); num[x]+=num[v]; } } int main() { scanf("%d%d",&n,&k); for (int i=1;i<n;i++){ int u,v; scanf("%d%d",&u,&v); add(u,v);add(v,u); } for (int v=1;v<=n;v++){ dep[v]=cnt=0; dfs(v,0); if (k&1){ int Max=0; for (int i=head[v];i;i=next[i]) Max=max(Max,num[w[i]]); cnt+=Max; } ans=max(ans,cnt); } printf("%d\n",n-ans); return 0; }
a.cc: In function 'void add(int, int)': a.cc:8:5: error: reference to 'next' is ambiguous 8 | next[cnt]=head[f]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:4:22: note: 'int next [100010]' 4 | int n,k,w[N],head[N],next[N]; | ^~~~ a.cc: In function 'void dfs(int, int)': a.cc:16:28: error: reference to 'next' is ambiguous 16 | for (int i=head[x];i;i=next[i]){ | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:4:22: note: 'int next [100010]' 4 | int n,k,w[N],head[N],next[N]; | ^~~~ a.cc: In function 'int main()': a.cc:37:36: error: reference to 'next' is ambiguous 37 | for (int i=head[v];i;i=next[i]) Max=max(Max,num[w[i]]); | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:4:22: note: 'int next [100010]' 4 | int n,k,w[N],head[N],next[N]; | ^~~~
s803720020
p04049
C++
#pragma comment(linker, "/stack:20000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> #include <array> using namespace std; #define TT1T2 template<class T1, class T2> TT1T2 void debug_print_array(const T1 &a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cerr << a[i] << (i + 1 != sz ? "," : ""); cout << endl; } #define DBN1(a) cerr<<#a<<"="<<(a)<<"\n" #define DBN2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n" #define DBN3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n" #define DA(a,n) cerr<<#a<<"=["; debug_print_array(a,n); cerr<<"]\n" double __begin; #define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl; using ll = long long; using ld = long double; using ull = unsigned long long; template <typename T, const int N> using Graph = vector <T> [N]; const int MAXN = 2222; const int INF = 1e9; Graph<int, MAXN> g; int d[MAXN][MAXN]; bool used[MAXN]; int h[MAXN]; int n, k; void dfs(int vertex) { used[vertex] = true; h[vertex] = 1; vector <int> v; for (int& to : g[vertex]) { if (!used[to]) { dfs(to); h[vertex] = max(h[vertex], h[to] + 1); v.push_back(to); } } for (int i = 0; i <= min(k, h[vertex]); i++) { if (i == 0) { int sz = 0; for (int to : v) { sz += d[to][0]; } sz++; d[vertex][0] = sz; continue; } d[vertex][i] = INF; for (int j = 0; j < v.size(); j++) { int cur = v[j]; if (h[cur] >= i - 1) { int cnt = d[cur][i - 1]; for (int p = 0; p < v.size(); p++) { if (p == j) { continue; } cnt += d[v[p]][min(h[v[p]], min(k - i, i - 1))]; } if (cnt < d[vertex][i]) { d[vertex][i] = cnt; } } } } if (h[vertex] == 1) { d[vertex][1] = 0; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(20); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> k; k++; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } int ans = INF; for (int j = 0; j < n; j++) { memset(used, 0, sizeof(used)); dfs(j); for (int i = 0; i <= min(k, h[j]); i++) { ans = min(ans, d[j][i]); } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:107:9: error: 'memset' was not declared in this scope 107 | memset(used, 0, sizeof(used)); | ^~~~~~ a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 10 | #include <array> +++ |+#include <cstring> 11 |
s061885573
p04049
C++
#include<cstdio> #include<algorithm> #include<cstring> #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; const int N=5e3+5; const int inf=1e9; int n,m,head[N],next[N],go[N],sum; int dis[2005][2005],tot; inline void add(int x,int y) { go[++tot]=y; next[tot]=head[x]; head[x]=tot; } inline void dfs(int x,int fa,int dep) { if (dep>(m/2))sum++; for(int i=head[x];i;i=next[i]) { int v=go[i]; if (v!=fa) { dfs(v,x,dep+1); } } } int main() { scanf("%d%d",&n,&m); fo(i,1,n-1) { int x,y; scanf("%d%d",&x,&y); add(x,y); add(y,x); } int ans=inf; fo(i,1,n) { sum=0; dfs(i,0,0); ans=min(ans,sum); } printf("%d\n",ans); }
a.cc: In function 'void add(int, int)': a.cc:14:9: error: reference to 'next' is ambiguous 14 | next[tot]=head[x]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/algorithm:60, from a.cc:2: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:9:17: note: 'int next [5005]' 9 | int n,m,head[N],next[N],go[N],sum; | ^~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:20:31: error: reference to 'next' is ambiguous 20 | for(int i=head[x];i;i=next[i]) | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:9:17: note: 'int next [5005]' 9 | int n,m,head[N],next[N],go[N],sum; | ^~~~
s723391172
p04049
C++
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <map> #include <queue> #include <deque> #include <set> #include <sstream> #include <utility> #include <list> #include <ctime> #include <memory> using namespace std; const int N=2050; vector<int> E[N]; int DFS(int x,int p,int d,int mx) { int ans=1; if(d!=mx){ for(int y=0;y<E[x].size();y++){ if(E[x][y]==p)continue; ans+=DFS(E[x][y],x,d+1,mx); } } return ans; } int main() { int n,k; cin >>n>>k; for(int i=0;i<n-1;i++){ int a,b; cin >>a>>b; a--;b--; E[a].push_back(b); E[b].push_back(a); } int ans=0; if(k%2==0){ for(int v=0;v<n;v++){ ans=max(ans,DFS(v,-1,0,k/2)); } } else { for(int v=0;v<n;v++){ for(int u=0;u<E[v].size();u++){ ans=max(ans,DFS(E[v][u],u,0,k/2)+DFS(u,E[v][u],0,k/2)); } } } ans=n-ans; if(and<0)ans=0; cout << ans; return 0; }
a.cc: In function 'int main()': a.cc:61:15: error: expected identifier before '<' token 61 | if(and<0)ans=0; | ^
s372648580
p04049
C++
#include <iostream> //#include <algorithm> //#include <cmath> #include <vector> //#include <stdlib.h> #include <queue> //#include <set> //#include <string> //#include <string.h> //#include <cstring> //#include <stdio.h> //#include <fstream> //#include <stack> //#include <iomanip> //#include <conio.h> //#include <windows.h> //#include <time.h> //#define rep(N) for(int i=0;i<N;i++) //#define ll long long //#define pii pair<int,int> //#define For(I,N) for(int I=0;I<N;I++) #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int); void bfs(int x) { fill(visit,visit+n,0); int t=x; queue<pair<int,int> >que; que.push(make_pair<int,int>(1,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[t][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } for(int i=0;i<n;i++) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc: In function 'void bfs(int)': a.cc:49:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 49 | que.push(make_pair<int,int>(vec[nx][i],s+1)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~
s078787088
p04049
C++
#include <iostream> //#include <algorithm> //#include <cmath> #include <vector> //#include <stdlib.h> #include <queue> //#include <set> //#include <string> //#include <string.h> //#include <cstring> //#include <stdio.h> //#include <fstream> //#include <stack> //#include <iomanip> //#include <conio.h> //#include <windows.h> //#include <time.h> //#define rep(N) for(int i=0;i<N;i++) //#define ll long long //#define pii pair<int,int> //#define For(I,N) for(int I=0;I<N;I++) #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int); void bfs(int x) { fill(visit,visit+n,0); int t=x; queue<pair<int,int> >que; que.push(make_pair<int,int>(t,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[t][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } for(int i=0;i<n;i++) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc: In function 'void bfs(int)': a.cc:38:37: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int' 38 | que.push(make_pair<int,int>(t,0)); | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~ a.cc:49:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 49 | que.push(make_pair<int,int>(vec[nx][i],s+1)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~
s055086973
p04049
C++
#include <iostream> //#include <algorithm> //#include <cmath> #include <vector> //#include <stdlib.h> #include <queue> //#include <set> //#include <string> //#include <string.h> //#include <cstring> //#include <stdio.h> //#include <fstream> //#include <stack> //#include <iomanip> //#include <conio.h> //#include <windows.h> //#include <time.h> //#define rep(N) for(int i=0;i<N;i++) //#define ll long long //#define pii pair<int,int> //#define For(I,N) for(int I=0;I<N;I++) #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int); void bfs(int x) { fill(visit,visit+n,0); queue <pair<int,int> >que; int t=x; que.push(make_pair<int,int>(t,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[t][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } for(int i=0;i<n;i++) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc: In function 'void bfs(int)': a.cc:38:37: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int' 38 | que.push(make_pair<int,int>(t,0)); | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~ a.cc:49:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 49 | que.push(make_pair<int,int>(vec[nx][i],s+1)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~
s473986613
p04049
C++
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <queue> #include <set> #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int x) { fill(visit,visit+n,0); queue <pair<int,int> >que; int t=x; que.push(make_pair<int,int>(t,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[t][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } for(int i=0;i<n;i++) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc: In function 'void bfs(int)': a.cc:23:37: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int' 23 | que.push(make_pair<int,int>(t,0)); | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~ a.cc:34:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 34 | que.push(make_pair<int,int>(vec[nx][i],s+1)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~
s504990477
p04049
C++
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <stdlib.h> #include <queue> #include <set> #include <string> #include <string.h> #include <cstring> #include <stdio.h> #include <fstream> #include <stack> #include <iomanip> //#include <conio.h> //#include <windows.h> //#include <time.h> #define rep(N) for(int i=0;i<N;i++) #define ll long long #define pii pair<int,int> #define For(I,N) for(int I=0;I<N;I++) #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int x) { fill(visit,visit+n,0); queue <pair<int,int> >que; int t=x; que.push(make_pair<int,int>(t,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[t][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } rep(n) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc: In function 'void bfs(int)': a.cc:37:37: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int' 37 | que.push(make_pair<int,int>(t,0)); | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~ a.cc:48:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 48 | que.push(make_pair<int,int>(vec[nx][i],s+1)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~
s227675766
p04049
C++
#include<iostream> #include<cctype> #include<queue> #include<cstdio> #include<cmath> #include<sstream> #include<string> #include<algorithm> #include<cstring> #include<vector> #include<ctime> #include<cstdlib> #include<map> #include<utility> #include<iomanip> #include<set> using namespace std; typedef long long ll; int n,k; const int N=4008; vector<int> g[N]; const int INF=(int)1e7+10; int ans=N; int q[4008]; int topQ; int dist[4008]; inline void bfs() { for(int k=0;k<topQ;k++) { int v=q[k]; for(int u : g[v]) { int w=dist[v]+2; if(dist[u]<=w) continue; dist[u]=w; q[topQ++]=u; } } return; } int solvedian(int v) { for(int i=0;i<n;i++) dist[i]=INF; dist[v]=0; topQ=0; q[topQ++]=v; bfs(); int res=0; for(int i=0;i<n;i++) if(dist[i]>k) res++; return res; } int solvebian() { for(int i=0;i<n;i++) dist[i]=INF; dist[v]=dist[u]=1; topQ=0; q[topQ++]=v; q[topQ++]=u; bfs(); int res=0; for(int i=0;i<n;i++) if(dist[i]>k) res++; return res; } int main () { cin>>n>>k; for(int i=1;i<n;i++) { int u,v; cin>>v>>u; v--; u--; g[v].push_back(u); g[u].push_back(v); } for(int v=0;v<n;v++) ans=min(ans,solvedian(v)); for(int v=0;v<n;v++) for(int u:g[v]) if(u>v) ans=min(ans,solvebian(v,u)); cout<<ans; return 0; }
a.cc: In function 'int solvebian()': a.cc:61:14: error: 'v' was not declared in this scope 61 | dist[v]=dist[u]=1; | ^ a.cc:61:22: error: 'u' was not declared in this scope 61 | dist[v]=dist[u]=1; | ^ a.cc: In function 'int main()': a.cc:89:54: error: too many arguments to function 'int solvebian()' 89 | ans=min(ans,solvebian(v,u)); | ~~~~~~~~~^~~~~ a.cc:57:5: note: declared here 57 | int solvebian() | ^~~~~~~~~
s338066450
p04049
C++
#include<iostream> #include<cctype> #include<queue> #include<cstdio> #include<cmath> #include<sstream> #include<string> #include<algorithm> #include<cstring> #include<vector> #include<ctime> #include<cstdlib> #include<map> #include<utility> #include<iomanip> #include<set> using namespace std; typedef long long ll; int n,k; const int N=4008; vector<int> g[N]; const int INF=(int)1e7+10; int ans=N; int q[4008]; int topQ; int dist[4008]; inline void bfs() { for(int k=0;k<topQ;k++) { int v=q[k]; for(int u : g[v]) { int w=dist[v]+2; if(dist[u]<=w) continue; dist[u]=w; q[topQ++]=u; } } return; } int solvedian() { for(int i=0;i<n;i++) dist[i]=INF; dist[v]=0; topQ=0; q[topQ++]=v; bfs(); int res=0; for(int i=0;i<n;i++) if(dist[i]>k) res++; return res; } int solvebian() { for(int i=0;i<n;i++) dist[i]=INF; dist[v]=dist[u]=1; topQ=0; q[topQ++]=v; q[topQ++]=u; bfs(); int res=0; for(int i=0;i<n;i++) if(dist[i]>k) res++; return res; } int main () { cin>>n>>k; for(int i=1;i<n;i++) { int u,v; cin>>v>>u; v--; u--; g[v].push_back(u); g[u].push_back(v); } for(int v=0;v<n;v++) ans=min(ans,solvedian(v)); for(int v=0;v<n;v++) for(int u:g[v]) if(u>v) ans=min(ans,solvebian(v,u)); cout<<ans; return 0; }
a.cc: In function 'int solvedian()': a.cc:47:14: error: 'v' was not declared in this scope 47 | dist[v]=0; | ^ a.cc: In function 'int solvebian()': a.cc:61:14: error: 'v' was not declared in this scope 61 | dist[v]=dist[u]=1; | ^ a.cc:61:22: error: 'u' was not declared in this scope 61 | dist[v]=dist[u]=1; | ^ a.cc: In function 'int main()': a.cc:85:38: error: too many arguments to function 'int solvedian()' 85 | ans=min(ans,solvedian(v)); | ~~~~~~~~~^~~ a.cc:43:5: note: declared here 43 | int solvedian() | ^~~~~~~~~ a.cc:89:54: error: too many arguments to function 'int solvebian()' 89 | ans=min(ans,solvebian(v,u)); | ~~~~~~~~~^~~~~ a.cc:57:5: note: declared here 57 | int solvebian() | ^~~~~~~~~
s574711903
p04049
C++
#include<iostream> #include<cctype> #include<queue> #include<cstdio> #include<cmath> #include<sstream> #include<string> #include<algorithm> #include<cstring> #include<vector> #include<ctime> #include<cstdlib> #include<map> #include<utility> #include<iomanip> #include<set> using namespace std; typedef long long ll; int n,k; const int N=4008; vector<int> g[N]; const int INF=(int)1e7+10; int ans=N; int q[4008]; int topQ; int dist[4008]; inline void bfs() { for(int k=0;k<topQ;k++) { int v=q[k]; for(int u : g[v]) { int w=dist[v]+2; if(dist[u]<=w) continue; dist[u]=w; q[topQ++]=u; } } return; } int solvedian() { for(int i=0;i<n;i++) dist[i]=INF; dist[v]=0; topQ=0; q[topQ++]=v; bfs(); itn res=0; for(int i=0;i<n;i++) if(dist[i]>k) res++; return res; } int solvebian() { for(int i=0;i<n;i++) dist[i]=INF; dist[v]=dist[u]=1; topQ=0; q[topQ++]=v; q[topQ++]=u; bfs(); int res=0; for(int i=0;i<n;i++) if(dist[i]>k) res++; return res; } int main () { cin>>n>>k; for(int i=1;i<n;i++) { int u,v; cin>>v>>u; v--; u--; g[v].push_back(u); g[u].push_back(v); } for(int v=0;v<n;v++) ans=min(ans,solvedian(v)); for(int v=0;v<n;v++) for(int u:g[v]) if(u>v) ans=min(ans,solvebian(v,u)); cout<<ans; return 0; }
a.cc: In function 'int solvedian()': a.cc:47:14: error: 'v' was not declared in this scope 47 | dist[v]=0; | ^ a.cc:51:9: error: 'itn' was not declared in this scope; did you mean 'int'? 51 | itn res=0; | ^~~ | int a.cc:54:25: error: 'res' was not declared in this scope 54 | res++; | ^~~ a.cc:55:16: error: 'res' was not declared in this scope 55 | return res; | ^~~ a.cc: In function 'int solvebian()': a.cc:61:14: error: 'v' was not declared in this scope 61 | dist[v]=dist[u]=1; | ^ a.cc:61:22: error: 'u' was not declared in this scope 61 | dist[v]=dist[u]=1; | ^ a.cc: In function 'int main()': a.cc:85:38: error: too many arguments to function 'int solvedian()' 85 | ans=min(ans,solvedian(v)); | ~~~~~~~~~^~~ a.cc:43:5: note: declared here 43 | int solvedian() | ^~~~~~~~~ a.cc:89:54: error: too many arguments to function 'int solvebian()' 89 | ans=min(ans,solvebian(v,u)); | ~~~~~~~~~^~~~~ a.cc:57:5: note: declared here 57 | int solvebian() | ^~~~~~~~~
s419698647
p04049
C++
#include <assert.h> #include <ctype.h> #include <errno.h> #include <float.h> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <locale> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <wchar.h> #include <wctype.h> #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <exception> #include <functional> #include <map> #include <ios> #include <iosfwd> #include <istream> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <vector> #include <cwchar> #include <cwctype> #include <complex.h> #include <fenv.h> #include <inttypes.h> #include <stdbool.h> #include <stdint.h> #include <tgmath.h> #include <conio.h> #include <numeric> #include <list> #include <windows.h> #include <cfloat> #include <climits> #include <unordered_map> #include <unordered_set> using namespace std; int n,k,sz,q[2010],dist[2010],ans=1e9; vector<int> pos[2010]; inline void bfs() { for(int i=0;i<sz;i++) { int cur=q[i]; for(int j:pos[cur]) { int w=dist[cur]+2; if(dist[j]<=w) continue; dist[j]=w; q[sz++]=j; } } } inline int solveVertex(int i) { fill(dist,dist+n,1e9); dist[i]=0; sz=0; q[sz++]=i; bfs(); int sum=0; for(int j=0;j<n;j++) if(dist[j]>k) sum++; return sum; } inline int solveEdge(int i,int j) { fill(dist,dist+n,1e9); dist[i]=dist[j]=1; sz=0; q[sz++]=i; q[sz++]=j; bfs(); int sum=0; for(int m=0;m<n;m++) if(dist[m]>k) sum++; return sum; } int main() { cin>>n>>k; for(int i=0;i<n-1;i++) { int a,b; cin>>a>>b; a--;b--; pos[a].push_back(b); pos[b].push_back(a); } for(int i=0;i<n;i++) ans=min(ans,solveVertex(i)); for(int i=0;i<n;i++) for(int j:pos[i]) if(j>i) ans=min(ans,solveEdge(i,j)); cout<<ans; return 0; }
a.cc:53:10: fatal error: conio.h: No such file or directory 53 | #include <conio.h> | ^~~~~~~~~ compilation terminated.
s718630910
p04049
C++
#include <iostream> #include <fstream> #include <cstdio> #include <cassert> #include <complex> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <cstdlib> #include <cstring> #include <iomanip> #include <numeric> #include <sstream> #include <ctime> #include <cctype> #include <set> #include <map> #include <queue> #include <bitset> #include <deque> #include <stack> #include <memory.h> using namespace std; #define ll long long int n,k; vector<int> nei[2050]; int dis[2050][2050]; bool crash[2050][2050]; int cnum[2050]; void bfs(int root){ queue<int> q; dis[root][root]=0; q.push(root); while(!q.empty()){ int last=q.front(); q.pop(); for(int i=0;i<nei[last].size();i++){ if(dis[root][nei[last][i]]==-1){ dis[root][nei[last][i]]=dis[root][last]+1; q.push(nei[last][i]); } } } } bool nocrash(){ for(int i=0;i<n;i++){ if(cnum[i]>0) return false; } return true; } int main(){ cin>>n>>k; for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; a--;b--; nei[a].push_back(b); nei[b].push_back(a); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ dis[i][j]=-1; } } for(int i=0;i<n;i++){ bfs(i); } for(int i=0;i<n;i++){ int num=0; for(int j=0;j<n;j++){ if(dis[i][j]>k){ crash[i][j]=true; num++; } } cnum[i]=num; } while(!nocrash()){ int mx=-1,imx=-1; for(int i=0;i<n;i++){ if(cnum[i]>mx){ mx=cnum[i]; imx=i; } } for(int i=0;i<n;i++){ crash[imx][i]=false; if(crash[i][imx]){ crash[i][imx]=false; cnum[i]--; } } cnum[imx]=-2; ans++; } cout<<ans; return 0; }
a.cc: In function 'int main()': a.cc:95:17: error: 'ans' was not declared in this scope; did you mean 'abs'? 95 | ans++; | ^~~ | abs a.cc:97:15: error: 'ans' was not declared in this scope; did you mean 'abs'? 97 | cout<<ans; | ^~~ | abs
s009469223
p04049
C++
v#include<stdio.h> #include<string> #include<math.h> #include<stdlib.h> #include<set> #include<bitset> #include<map> #include<vector> #include<string.h> #include<algorithm> #include<iostream> #include<queue> #include<deque> #include<stack> using namespace std; int n,l,ans; vector<int> nei[2005]; int dfs(int x,int p,int d,int mx){ int ans=1; if(d!=mx) for(int i=0;i<nei[x].size();i++) if(nei[x][i]!=p) ans+=dfs(nei[x][i],x,d+1,mx); return ans; } int main(){ cin>>n>>l; for(int i=0;i<n-1;i++){ int x,y; cin>>x>>y; nei[x].push_back(y); nei[y].push_back(x); } if(l%2==0) for(int i=1;i<=n;i++) ans=max(ans,dfs(i,-1,0,l/2)); else for(int i=1;i<=n;i++) for(int j=0;j<nei[i].size();j++) ans=max(ans,dfs(i,nei[i][j],0,l/2)+dfs(nei[i][j],i,0,l/2)); cout<<n-ans<<endl; return 0; }
a.cc:1:2: error: stray '#' in program 1 | v#include<stdio.h> | ^ a.cc:1:1: error: 'v' does not name a type 1 | v#include<stdio.h> | ^ In file included from /usr/include/c++/14/bits/char_traits.h:42, from /usr/include/c++/14/string:42, from a.cc:2: /usr/include/c++/14/bits/postypes.h:68:11: error: 'ptrdiff_t' does not name a type 68 | typedef ptrdiff_t streamsize; // Signed integral type | ^~~~~~~~~ /usr/include/c++/14/bits/postypes.h:41:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>' 40 | #include <cwchar> // For mbstate_t +++ |+#include <cstddef> 41 | In file included from /usr/include/c++/14/bits/char_traits.h:50: /usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std' 666 | struct is_null_pointer<std::nullptr_t> | ^~~~~~~~~ /usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid 666 | struct is_null_pointer<std::nullptr_t> | ^ /usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid 670 | struct is_null_pointer<const std::nullptr_t> | ^ /usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid 674 | struct is_null_pointer<volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid 678 | struct is_null_pointer<const volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^~~~~~ In file included from /usr/include/wchar.h:35, from /usr/include/c++/14/cwchar:44, from /usr/include/c++/14/bits/postypes.h:40: /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^ /usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1438 | : public integral_constant<std::size_t, 0> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid 1438 | : public integral_constant<std::size_t, 0> { }; | ^ /usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared 1440 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope 1441 | struct rank<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid 1441 | struct rank<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:2086:26: error: 'std::size_t' has not been declared 2086 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2087:30: error: '_Size' was not declared in this scope 2087 | struct remove_extent<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2087:36: error: template argument 1 is invalid 2087 | struct remove_extent<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2099:26: error: 'std::size_t' has not been declared 2099 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2100:35: error: '_Size' was not declared in this scope 2100 | struct remove_all_extents<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2100:41: error: template argument 1 is invalid 2100 | struct remove_all_extents<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2171:12: error: 'std::size_t' has not been declared 2171 | template<std::size_t _Len> | ^~~ /usr/include/c++/14/type_traits:2176:30: error: '_Len' was not declared in this scope 2176 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2194:12: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2194:30: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2195:55: error: '_Len' was not declared in this scope 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^~~~ /usr/include/c++/14/type_traits:2195:59: error: template argument 1 is invalid 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^ /usr/include/c++/14/type_traits:2202:30: error: '_Len' was not declared in this scope 2202 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2203:44: error: '_Align' was not declared in this scope 2203 | struct __attribute__((__aligned__((_Align)))) { } __align; | ^~~~~~ /usr/include/c++/14/bits/char_traits.h:144:61: error: 'std::size_t' has not been declared 144 | compare(const char_type* __s1, const char_type* __s2, std::size_t __n); | ^~~ /usr/include/c++/14/bits/char_traits.h:146:40: error: 'size_t' in namespace 'std' does not name a type 146 | static _GLIBCXX14_CONSTEXPR std::size_t | ^~~~~~ /usr/include/c++/14/bits/char_traits.h:150:34: error: 'std::size_t' has not been declared 150 | find(const char_type* __s, std::size_t __n, const char_type& __a); | ^~~ /usr/include/c++/14/bits/char_traits.h:153:52: error: 'std::size_t' has not been declared 153 | move(char_type* __s1, const char_type* __s2, std::size_t __n); | ^~~ /usr/include/c++/14/bits/char_traits.h:156:52: error: 'std::size_t' has not been declared 156 | copy(char_type* __s1, const char_type* __s2, std::size_t __n); | ^~~ /usr/include/c++/14/bits/char_traits.h:159:30: error: 'std::size_t' has not been declared 159 | assign(char_type* __s, std::size_t __n, char_type __a); | ^~~ /usr/include/c++/14/bits/char_traits.h:187:59: error: 'std::size_t' has not been declared 187 | compare(const char_type* __s1, const char_type* __s2, std::size_t __n) | ^~~ /usr/include/c++/14/bits/char_traits.h: In static member function 'static constexpr int __gnu_cxx::char_traits<_CharT>::compare(const char_type*, const char_type*, int)': /usr/include/c++/14/bits/char_traits.h:189:17: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 189 | for (std::size_t __i = 0; __i < __n; ++__i) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/bits/char_traits.h:189:33: error: '__i' was not declared in this scope; did you mean '__n'? 189 | for (std::size_t __i = 0; __i < __n; ++__i) | ^~~ | __n /usr/include/c++/14/bits/char_traits.h: At global scope: /usr/include/c++/14/bits/char_traits.h:198:31: error: 'size_t' in namespace 'std' does not name a typ
s818719744
p04049
C++
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <stdlib.h> #include <queue> #include <set> #include <string> #include <string.h> #include <cstring> #include <stdio.h> #include <fstream> #include <stack> #include <iomanip> //#include <conio.h> //#include <windows.h> //#include <time.h> #define rep(N) for(int i=0;i<N;i++) #define ll long long #define pii pair<int,int> #define For(I,N) for(int I=0;I<N;I++) #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int x) { fill(visit,visit+n,0); queue <pair<int,int> >que; int t=x; que.push(make_pair<int,int>(t,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[t][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } rep(n) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc: In function 'void bfs(int)': a.cc:37:37: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int' 37 | que.push(make_pair<int,int>(t,0)); | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~ a.cc:48:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 48 | que.push(make_pair<int,int>(vec[nx][i],s+1)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~
s814336180
p04049
C++
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <stdlib.h> #include <queue> #include <set> #include <string> #include <string.h> #include <cstring> #include <stdio.h> #include <fstream> #include <stack> #include <iomanip> //#include <conio.h> //#include <windows.h> //#include <time.h> #define rep(N) for(int i=0;i<N;i++) #define ll long long #define pii pair<int,int> #define For(I,N) for(int I=0;I<N;I++) #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int x) { fill(visit,visit+n,0); queue <pair<int,int> >que; int t=x; que.push(make_pair<int,int>(t,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[t][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } rep(n) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc: In function 'void bfs(int)': a.cc:37:37: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int' 37 | que.push(make_pair<int,int>(t,0)); | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~ a.cc:48:52: error: cannot bind rvalue reference of type 'int&&' to lvalue of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} 48 | que.push(make_pair<int,int>(vec[nx][i],s+1)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1132:21: note: initializing argument 1 of 'constexpr std::pair<typename std::__strip_reference_wrapper<typename std::decay<_Tp>::type>::__type, typename std::__strip_reference_wrapper<typename std::decay<_Tp2>::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = int; _T2 = int; typename __strip_reference_wrapper<typename decay<_Tp>::type>::__type = int; typename decay<_Tp>::type = int; typename __strip_reference_wrapper<typename decay<_Tp2>::type>::__type = int; typename decay<_Tp2>::type = int]' 1132 | make_pair(_T1&& __x, _T2&& __y) | ~~~~~~^~~
s266203411
p04049
C++
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> #include <memory.h> using namespace std; int n,k; vector<int> adj[2005]; int bfs(int v,int r,int prv=-1){ if(r>0){ int sum=1; for(int i=0;i<adj[v].size();i++){ if(adj[v][i]!=prv){ int s=bfs(adj[v][i],r-1,v); sum+=s; } } return sum; } else return 1; } int main(){ scanf("%d %d",&n,&k); for(int i=1;i<=n-1;i++){ int a,b; scanf("%d %d",&a,&b); adj[a].push_back(b); adj[b].push_back(a); } if(k%2==0){ int r=k/2,mint=1e6; for(int i=1;i<=n;i++){ mint=min(mint,n-bfs(i,r)); } printf("%d\n",mint); } else{ int r=k/2,mint=1e6; for(int i=1;i<=n;i++){ int maxm=0 for(int j=0;j<adj[i].size();j++){ maxm=max(maxm,bfs(i,r)-bfs(adj[i][j],r-1,i)+bfs(adj[i][j],r,i)); } mint=min(mint,n-maxm>0?n-maxm:0); } printf("%d\n",mint); } return 0; }
a.cc: In function 'int main()': a.cc:62:25: error: expected ',' or ';' before 'for' 62 | for(int j=0;j<adj[i].size();j++){ | ^~~ a.cc:62:37: error: 'j' was not declared in this scope 62 | for(int j=0;j<adj[i].size();j++){ | ^
s098657552
p04049
C++
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <stdlib.h> #include <queue> #include <set> #include <string> #include <string.h> #include <cstring> #include <stdio.h> #include <fstream> #include <stack> #include <iomanip> #include <conio.h> #include <windows.h> #include <time.h> #define rep(N) for(int i=0;i<N;i++) #define ll long long #define pii pair<int,int> #define For(I,N) for(int I=0;I<N;I++) #define rep(N) for(int i=0;i<N;i++) using namespace std; vector <int> vec[2005]; vector <pair<int,int> >num[2005]; bool visit[2005]; int leaf[2005]; int dist[2005][2005]; int n,k; vector <int> leave; void bfs(int x) { fill(visit,visit+n,0); queue <pair<int,int> >que; que.push(make_pair<int,int>(x,0)); while(!que.empty()) { int nx=que.front().first; int s=que.front().second; que.pop(); for(int i=0;i<vec[nx].size();i++) { if(visit[vec[nx][i]]) continue; visit[vec[nx][i]]=true; dist[x][vec[nx][i]]=s+1; que.push(make_pair<int,int>(vec[nx][i],s+1)); } } } int main() { // freopen("input.txt","r",stdin); cin>>n>>k; int x,y; rep(n-1) { cin>>x>>y; vec[--x].push_back(--y); vec[y].push_back(x); leaf[x]++; leaf[y]++; } rep(n) { bfs(i); } // rep(n) // { // dist[i][i]=0; // for(int j=0;j<n;j++) // { // cout<<dist[i][j]<<" "; // } // cout<<endl; // } int s=0,mini=0; bool ok[n]; fill(ok,ok+n,0); rep(n) { dist[i][i]=0; if(ok[i]) continue; for(int j=0;j<n;j++) { if(ok[j]==1) continue; if(dist[i][j]>k) ok[j]=1; } } rep(n) { s+=ok[i]; } cout<<s<<endl; return 0; }
a.cc:15:10: fatal error: conio.h: No such file or directory 15 | #include <conio.h> | ^~~~~~~~~ compilation terminated.
s030768815
p04049
C++
#include<iostream> #include<cctype> #include<queue> #include<cstdio> #include<cmath> #include<sstream> #include<string> #include<algorithm> #include<cstring> #include<vector> #include<ctime> #include<cstdlib> #include<map> #include<utility> #include<iomanip> #include<set> using namespace std; typedef long long ll; int N,K; int cnt=0; vector<int> vec; vector<int> vt; map<int,int> mp; int maxN=2000; int a[2005],b[2005]; set<int> s; int main () { cin>>N>>K; for(int i=1;i<maxN;i++) { cin>>a[i]>>b[i]; mp[(long long)b[i]]=a[i]; s.insert(mp[b[i]]);cnt++; cnt.push_back(vec); } sort(vec.begin(),vec.end()); int q=vec.max; if(q>K) cout<<q-K; else cout<<0 return 0; }
a.cc: In function 'int main()': a.cc:35:21: error: request for member 'push_back' in 'cnt', which is of non-class type 'int' 35 | cnt.push_back(vec); | ^~~~~~~~~ a.cc:38:19: error: 'class std::vector<int>' has no member named 'max' 38 | int q=vec.max; | ^~~ a.cc:40:21: error: expected ';' before 'return' 40 | else cout<<0 | ^ | ; 41 | return 0; | ~~~~~~
s401156982
p04049
C++
#include <iostream> #include <algorithm> #include <math.h> #include <string> #include <cstdio> #include <vector> #include <set> #include <cassert> #include <cstdlib> #include <complex> #include <cctype> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <map> #include <set> #include <sstream> #include <functional> using namespace std; /**==Info== *Program:1 *Problem:Shorten Diameter *Date:2017-8-8 *Algorithm:DFS *Stats:Unknown*/ int n,k; vector<int> nei[2050]; int dis[2050][2050]; bool crash[2050][2050]; int cnum[2050]; //Crash Number void bfs(int root){ queue<int> q; dis[root][root]=0; q.push(root); while(!q.empty()){ int last=q.front(); q.pop(); for(int i=0;i<nei[last].size();i++){ if(dis[root][nei[last][i]]==-1){ dis[root][nei[last][i]]=dis[root][last]+1; q.push(nei[last][i]); //cout<<"Push yoU!"<<endl; } } } } bool nocrash(){ for(int i=0;i<n;i++){ if(cnum[i]>0) return false; } return true; } int main(){ cin>>n>>k; for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; a--;b--; nei[a].push_back(b); nei[b].push_back(a); } memset(dis,-1,2050*2050); for(int i=0;i<n;i++){ bfs(i); } // for(int i=0;i<n;i++){ // for(int j=0;j<n;j++){ // cout<<dis[i][j]<<" "; // } // cout<<endl; // } //Find crash for(int i=0;i<n;i++){ int num=0; for(int j=0;j<n;j++){ if(dis[i][j]>k){ crash[i][j]=true; num++; } } cnum[i]=num; } // cout<<"Oops"<<endl; int ans=0; // for(int i=0;i<n;i++){ // cout<<cnum[i]<<" "; // } // cout<<endl; while(!nocrash()){ //Find the biggest crasher!!!! int mx=-1,imx=-1; for(int i=0;i<n;i++){ if(cnum[i]>mx){ mx=cnum[i]; imx=i; } } //Then Kill It for(int i=0;i<n;i++){ crash[imx][i]=false; if(crash[i][imx]){ crash[i][imx]=false; cnum[i]--; } } cnum[imx]=-2; ans++; } cout<<ans; return 0; }
a.cc: In function 'int main()': a.cc:67:9: error: 'memset' was not declared in this scope 67 | memset(dis,-1,2050*2050); | ^~~~~~ a.cc:21:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 20 | #include <functional> +++ |+#include <cstring> 21 |
s282344497
p04049
C++
#include <bits/stdc++.h> #define ll long long #define uint unsigned long long #define ls x << 1 #define rs x << 1 | 1 #define pb push_back #define mp make_pair #define pii pair<int, int> #define X first #define Y second #define pcc pair<char, char> #define vi vector<int> #define vl vector<ll> #define rep(i, x, y) for(int i = x; i <= y; i ++) #define rrep(i, x, y) for(int i = x; i >= y; i --) #define eps 1e-9 using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int inf = 1e9; vector<int>g[2010]; int dp[2010][2010], dp2[2010][2010], K, v[2010]; void dfs(int x, int fa) { v[x] = 1; int s = (int)g[x].size(); rep(i, 0, s - 1) { if(fa == g[x][i])continue; dfs(g[x][i], x); v[x] += v[g[x][i]]; } rep(i, 0, s) rep(j, 0, K) dp2[i][j] = -inf; dp2[0][0] = 1; int sz = 0, now = 0; rep(i, 0, s - 1) { if(fa == g[x][i]) continue; rep(j, 0, sz) { dp2[now + 1][j] = max(dp2[now + 1][j], dp2[now][j]); for(int k = 0; j + k + 1 <= K; k ++) dp2[now + 1][max(j, k + 1)] = max(dp2[now + 1][max(j, k + 1)], dp2[now][j] + dp[g[x][i]][k]); } now ++; sz += v[g[x][i]]; } rep(i, 0, K) dp[x][i] = dp2[now][i]; } int main() { int n, k; n = read(); k = read(); K = k; rep(i, 1, n - 1) { int u, v; u = read(); v = re ad(); u --, v --; g[u].push_back(v); g[v].push_back(u); } dfs(0, -1); int ret = 0; rep(i, 0, n - 1) rep(j, 0, k) ret = max(ret, dp[i][j]); printf("%d\n", n - ret); return 0; }
a.cc: In function 'int main()': a.cc:67:21: error: 're' was not declared in this scope; did you mean 'rs'? 67 | v = re ad(); | ^~ | rs
s487510022
p04049
C++
#include <iostream> #include <vector> using namespace std; int solve(int root, int N, int K, const vector<vector<int>> &Es){ if (K == 1) return N - 2; if (K == 2){ int ans = 0; for (const auto &e : Es) ans = max(ans, e.size()); return N - ans - 1; } int k = K / 2; vector<int> depth(N, -1); depth[root] = 0; vector<int> parent(N, -1); parent[root] = root; vector<int> child(N, 0); vector<int> childKp1(N, 0); vector<bool> closed(N, false); vector<int> stack = {root}; while (not stack.empty()){ int v = stack.back(); if (closed[v]){ stack.pop_back(); childKp1[parent[v]] += childKp1[v]; child[parent[v]] += child[v] + 1; continue; } for (int u : Es[v]){ if (depth[u] != -1) continue; depth[u] = depth[v] + 1; parent[u] = v; if (depth[u] == k + 1){ ++childKp1[v]; continue; } stack.push_back(u); } closed[v] = true; } int cum = 1; int maxKp1 = 0; for (int v : Es[root]){ cum += child[v] + 1; maxKp1 = max(maxKp1, childKp1[v]); } int ans = N - cum; if (K & 1) ans -= maxKp1; return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<vector<int>> Es(N, vector<int>()); for (int i = 0; i != N - 1; ++i){ int a, b; cin >> a >> b; Es[a - 1].push_back(b - 1); Es[b - 1].push_back(a - 1); } int ans = N; for (int v = 0; v != N; ++v){ ans = min(ans, solve(v, N, K, Es)); } cout << ans << endl; return 0; }
a.cc: In function 'int solve(int, int, int, const std::vector<std::vector<int> >&)': a.cc:9:43: error: no matching function for call to 'max(int&, std::vector<int>::size_type)' 9 | for (const auto &e : Es) ans = max(ans, e.size()); | ~~~^~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:9:43: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<int>::size_type' {aka 'long unsigned int'}) 9 | for (const auto &e : Es) ans = max(ans, e.size()); | ~~~^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
s880036671
p04049
C++
#include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; int N,K; int dp[1005][1005]; int maxi[1005]; int s[1005]; int nr[1005]; vector<int> G[1005]; void dfs(int nod,int tata) { dp[nod][0]=1; maxi[nod]=nr[nod]=1; for(auto it:G[nod]){if(tata!=it){dfs(it,nod)nr[nod]+=nr[it];};} for(auto it:G[nod]) if(tata!=it) { fill_n(s+1,K+1,1<<30); s[0]=dp[nod][0]+dp[it][0]; for(int j=0;j<=maxi[it]&&j<K+1;j++) for(int k=1;k<=maxi[nod]&&k<=K+1-j;k++) s[max(k,j+1)]=min(s[max(k,j+1)],dp[nod][k]+dp[it][j]); for(int i=1;i<=K+1;i++)s[i]=min(s[i-1],s[i]); memcpy(dp[nod],s,sizeof(s)); maxi[nod]=max(maxi[nod],maxi[it]+1); } } int main() { cin>>N>>K; for(int i=1;i<N;i++) { int a,b; cin>>a>>b; G[a].push_back(b); G[b].push_back(a); } dfs(1,0); int ans=1<<30; for(int i=1;i<=N;i++) for(int j=0;j<=K+1;j++) ans=min(ans,dp[i][j]+nr[1]-nr[j]); cout<<ans; return 0; }
a.cc: In function 'void dfs(int, int)': a.cc:16:49: error: expected ';' before 'nr' 16 | for(auto it:G[nod]){if(tata!=it){dfs(it,nod)nr[nod]+=nr[it];};} | ^~ | ;
s374528167
p04049
C++
# include <iostream> # include <vector> # define DIM 2010 using namespace std; vector<int> Lista[DIM]; int Marcat[DIM],f[DIM],n,k,x,y,i,sol,maxim; void dfs(int nc){ for(int i=0;i<Lista[nc].size();i++){ int nv=Lista[nc][i]; if(Marcat[nv]==0){ Marcat[nv]=Marcat[nc]+1; dfs(nv); } } } int main () { cin>>n>>k; for(i=1;i<n;i++){ cin>>x>>y; Lista[x].push_back(y); Lista[y].push_back(x); } for(;;){ for(i=1;i<=n;i++) Marcat[i]=f[i]; Marcat[1]=1; maxim=0; dfs(1); for(i=1;i<=n;i++) if(maxim<Marcat[i]){ maxim=Marcat[i]; x=i; } for(i=1;i<=n;i++) Marcat[i]=f[i]; Marcat[x]=1; maxim=0; dfs(x); for(i=1;i<=n;i++) if(maxim<Marcat[i]){ maxim=Marcat[i]; y=i; } maxim--; if(maxim<=k){ cout<<sol<<"\n"; return 0; } sol++; f[x]=-1; fout<<x<<"\n"; } return 0; }
a.cc: In function 'int main()': a.cc:51:9: error: 'fout' was not declared in this scope 51 | fout<<x<<"\n"; | ^~~~
s929630596
p04049
C++
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<string> #include<stack> #include<queue> #include<vector> #include<map> #include<set> #include<algorithm> #define rep(n) for(int i=0;i<n;i++) #define repp(j, n) for(int j=0;j<n;j++) #define reppp(i, m, n) for(int i=m;i<=n;i++) #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define MOD 1000000007 #define MAX 1000000001 #define INF 1410065408 #define EPS 1e-9 using namespace std; typedef long long ll; typedef pair<ll, ll> P; struct edge{int from, to; ll cost;}; ll N, K; ll walk_even(ll node, vector<ll> es[], ll depth, vector<bool> use){ use[node] = true; ll ret = 0; for(ll next : es[node]){ if(!use[next]) ret += walk_even(next, es, depth+1, use); } if(depth > K/2) ret++; return ret; } signed main(){ cin >> N >> K; vector<P> es_odd; vector<ll> es_even[N]; rep(N-1){ ll from, to; cin >> from >> to; from--; to--; es_odd.push_back(P(from, to)); es_even[from].push_back(to); es_even[to].push_back(from); } vector<ll> ans; if(K % 2 == 0){ rep(N){ ans.push_back(walk_even(i, es_even, 0, vector<bool>(N, false))); } }else{ rep(P e : es_odd){ vector<bool> use(N, false); use[e.second] = true; tmp1 = walk_even(e.first, es_even, 0, use); use[e.second] = false; use[e.first] = true; tmp2 = walk_even(e.second, es_even, 0, use); ans.push_back(min(tmp1, tmp2)); } } cout << *min_element(all(ans)); }
a.cc: In function 'int main()': a.cc:13:28: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions] 13 | #define rep(n) for(int i=0;i<n;i++) | ^ a.cc:60:17: note: in expansion of macro 'rep' 60 | rep(P e : es_odd){ | ^~~ a.cc:60:23: error: expected primary-expression before 'e' 60 | rep(P e : es_odd){ | ^ a.cc:13:30: note: in definition of macro 'rep' 13 | #define rep(n) for(int i=0;i<n;i++) | ^ a.cc:13:35: error: expected ';' before ')' token 13 | #define rep(n) for(int i=0;i<n;i++) | ^ a.cc:60:17: note: in expansion of macro 'rep' 60 | rep(P e : es_odd){ | ^~~ a.cc:62:29: error: 'e' was not declared in this scope 62 | use[e.second] = true; | ^ a.cc:63:25: error: 'tmp1' was not declared in this scope; did you mean 'tm'? 63 | tmp1 = walk_even(e.first, es_even, 0, use); | ^~~~ | tm a.cc:65:25: error: 'tmp2' was not declared in this scope; did you mean 'tm'? 65 | tmp2 = walk_even(e.second, es_even, 0, use); | ^~~~ | tm
s622092738
p04049
C++
#include "iostream" #include "climits" #include "list" #include "queue" #include "set" #include "functional" #include "algorithm" #include "math.h" #include "utility" using namespace std; const long long int MOD = 1000000007; long long int N,K; list <int>edge[2001]; int dis[2001][2001]; int s, e; bool flag[2001] = {}; queue<int>Q; int f; int box[2001]; int bag; int ans; int main() { cin >> N>>K; for (int i = 1; i <= N; i++) { flag[i] = true; } for (int i = 0; i < N-1; i++) { cin >> s >> e; edge[s].insert(e); edge[e].insert(s); } while(1){ for (int i = 1; i <= N; i++) { box[i] = 0; if (flag[i]) { for (int j = 1; j <= N; j++) { if (i != j) { dis[i][j] = INT_MAX; } } Q.push(i); while (!Q.empty()) { f = Q.front(); for (auto j = edge[f].begin(); j != edge[f].end(); ++j) { if (flag[*j]) { if (dis[i][*j] > dis[i][f] + 1) { dis[i][*j] = dis[i][f] + 1; Q.push(*j); if (dis[i][*j] > K) { box[i]++; } } } } Q.pop(); } if (box[i])bag++; } } bag = 0; for (int i = 1; i <= N; i++) { bag = max(bag, box[i]); } if (bag) { ans++; for (int i = 1; i <= N; i++) { if (box[i] == bag) { flag[i] = false; break; } } } else break; } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:32:31: error: no matching function for call to 'std::__cxx11::list<int>::insert(int&)' 32 | edge[s].insert(e); | ~~~~~~~~~~~~~~^~~ In file included from /usr/include/c++/14/list:65, from a.cc:3: /usr/include/c++/14/bits/stl_list.h:1491:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = int; _Alloc = std::allocator<int>]' 1491 | insert(const_iterator __position, _InputIterator __first, | ^~~~~~ /usr/include/c++/14/bits/stl_list.h:1491:9: note: candidate expects 3 arguments, 1 provided In file included from /usr/include/c++/14/list:66: /usr/include/c++/14/bits/list.tcc:101:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]' 101 | list<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/list.tcc:101:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_list.h:1411:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]' 1411 | insert(const_iterator __position, value_type&& __x) | ^~~~~~ /usr/include/c++/14/bits/stl_list.h:1411:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_list.h:1430:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator]' 1430 | insert(const_iterator __p, initializer_list<value_type> __l) | ^~~~~~ /usr/include/c++/14/bits/stl_list.h:1430:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/list.tcc:117:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; size_type = long unsigned int; value_type = int]' 117 | list<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/list.tcc:117:5: note: candidate expects 3 arguments, 1 provided a.cc:33:31: error: no matching function for call to 'std::__cxx11::list<int>::insert(int&)' 33 | edge[e].insert(s); | ~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/stl_list.h:1491:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = int; _Alloc = std::allocator<int>]' 1491 | insert(const_iterator __position, _InputIterator __first, | ^~~~~~ /usr/include/c++/14/bits/stl_list.h:1491:9: note: candidate expects 3 arguments, 1 provided /usr/include/c++/14/bits/list.tcc:101:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]' 101 | list<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/list.tcc:101:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_list.h:1411:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; value_type = int]' 1411 | insert(const_iterator __position, value_type&& __x) | ^~~~~~ /usr/include/c++/14/bits/stl_list.h:1411:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_list.h:1430:7: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator]' 1430 | insert(const_iterator __p, initializer_list<value_type> __l) | ^~~~~~ /usr/include/c++/14/bits/stl_list.h:1430:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/list.tcc:117:5: note: candidate: 'std::__cxx11::list<_Tp, _Alloc>::iterator std::__cxx11::list<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; iterator = std::__cxx11::list<int>::iterator; const_iterator = std::__cxx11::list<int>::const_iterator; size_type = long unsigned int; value_type = int]' 117 | list<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/list.tcc:117:5: note: candidate expects 3 arguments, 1 provided
s477364428
p04049
C++
#include<algorithm> #include<iostream> #include<vector> #include<utility> #define INF 10000 using namespace std; typedef long long ll; typedef pair<int, int> P; enum { MaxEdge = 2000 }; int dist[MaxEdge][MaxEdge]; int main() { int n, k; cin >> n >> k; vector<int> edge[MaxEdge]; memset(dist, INF, sizeof(dist)); vector<pair<int, int>> E; for (int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; a--; b--; dist[a][b] = 1; dist[b][a] = 1; E.push_back(P(a, b)); } for (int i = 0; i < n; i++) { dist[i][i] = 0; } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } if (k % 2 == 0) { int ans = INF; for (int i = 0; i < n; i++) { int a = 0; for (int j = 0; j < n; j++) { if (dist[i][j] > k/2)a++; } ans = min(ans, a); } cout << ans << endl; } else { int ans = INF; for (int i = 0; i < E.size(); i++) { int a = 0; for (int j = 0; j < n; j++) { if (dist[E[i].first][j] > k/2&&dist[E[i].second][j]>k/2) { a++; } } ans = min(ans, a); } cout << ans << endl; } }
a.cc: In function 'int main()': a.cc:16:9: error: 'memset' was not declared in this scope 16 | memset(dist, INF, sizeof(dist)); | ^~~~~~ a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 4 | #include<utility> +++ |+#include <cstring> 5 | #define INF 10000
s382058223
p04049
C++
#ifdef LOCAL111 #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include <bits/stdc++.h> const int INF = 1e9; using namespace std; template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; } //library typedef long long cost_t; class Edge { public: int to; cost_t cost; Edge(){ } Edge(int x,cost_t y){ to = x; cost = y; } bool operator< (const Edge& x) const { if(cost != x.cost) return cost < x.cost; return to < x.to; } bool operator> (const Edge& x) const { if(cost != x.cost) return cost > x.cost; return to > x.to; } }; class Graph { private: //const long long int INF = (long long)1e18; vector<vector<Edge> > v; int n; public: Graph(int x){ n = x; v = vector<vector<Edge> >(x); } vector<Edge>& operator[](int x){ return v[x]; } const vector<Edge>& operator[](int x) const { return v[x]; } int size() const { return n; } void add_edge(int from, Edge e){ v[from].push_back(e); } void add_edge(int from, int to, cost_t cost){ add_edge(from,Edge(to,cost)); } void add_uedge(int from, int to, cost_t cost){ add_edge(from,to,cost); add_edge(to,from,cost); } }; vector<cost_t> dijkstra(int from, const Graph& v) { vector<cost_t> dist(v.size(),INF); priority_queue<Edge,vector<Edge>,greater<Edge>> que; que.push(Edge(from,0)); while(!que.empty()){ Edge e = que.top(); que.pop(); if(dist[e.to] == INF){ dist[e.to] = e.cost; for(auto to : v[e.to]){ if(dist[to.to] == INF) que.push(Edge(to.to, e.cost+to.cost)); } } } return dist; } vector<cost_t> bellmanford(int from, const Graph& g) { vector<cost_t> res(g.size(),INF); res[from] = 0; bool conf = true; int cnt = 0; while(conf){ conf = false; for(int i = 0; i < g.size(); i++){ if(res[i] != INF) for(const auto& e : g[i]){ if(res[e.to] > res[i]+e.cost){ conf = true; res[e.to] = res[i]+e.cost; } } } if(cnt > g.size()+5) return vector<cost_t>(); cnt++; } return res; } Graph prim(const Graph g) { using T = tuple<cost_t, int, int>; priority_queue<T, vector<T>, greater<T>> qu; int n = g.size(); assert(n != 0); vector<bool> added(n,false); qu.emplace(0,0,0); Graph res(n); while(!qu.empty()){ int from, to; cost_t cost; tie(cost, from, to) = qu.top(); qu.pop(); if(!added[to]){ added[to] = true; res.add_edge(from, to, cost); res.add_edge(to, from, cost); for(const auto &e : g[to]){ if(!added[e.to]){ qu.emplace(e.cost, to, e.to); } } } } return res; } vector<int> tree_getorder(const Graph &g, int root) { vector<int> res; function<void(int p, int pre)> func = [&](int p, int pre){ for(auto &e : g[p]){ if(e.to != pre){ func(e.to,p); } } res.push_back(p); }; func(root,-1); return res; } vector<int> tree_getpar(const Graph &g, int root) { vector<int> par(g.size(),root); function<void(int p, int pre)> func = [&](int p, int pre){ par[p] = pre; for(auto &e : g[p]){ if(e.to != pre){ func(e.to,p); } } }; func(root,root); return par; } //未検証 vector<int> toposort(const Graph &g, int start) { int n = g.size(); vector<int> res; res.reserve(n); vector<bool> used(n,false); function<void(int)> rec = [&](int p){ if(used[p]) return; used[p] = true; for(auto&& e : g[p]) { rec(e.to); } res.push_back(p); }; rec(start); return res; } //liblary void vizGraph(const Graph &g, bool with_dir = false, bool with_cap = false){ ofstream ofs("./out.dot"); if(with_dir) ofs << "graph graph_name {" << endl; else ofs << "digraph graph_name {" << endl; for(int i = 0; i < (int)g.size(); i++){ if (!g[i].size()) continue; for(const auto &e : g[i]){ if(with_dir){ if(e.to > i) ofs << " \"" << i << "\" -- \"" << e.to << '"'; }else ofs << " \"" << i << "\" -> \"" << e.to << '"'; if (with_cap) { ofs << " [ label = \"" << (e.cost == INF ? "inf" : to_string(e.cost)) << "\"];"; } if(!with_dir or e.to > i)ofs << endl; } } ofs << "}" << endl; ofs.close(); system("dot -T png out.dot > sample.png"); } #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #ifdef LOCAL111 #define DEBUG(x) cout<<#x<<": "<<(x)<<endl template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;} #else #define DEBUG(x) true template<typename T> void dpite(T a, T b){ return; } #endif #define F first #define S second #define SNP string::npos #define WRC(hoge) cout << "Case #" << (hoge)+1 << ": " template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;} template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} typedef long long int LL; typedef unsigned long long ULL; typedef pair<int,int> P; typedef pair<LL,LL> LP; tuple<cost_t,int,int> getTreeDiameter(const Graph &g){ using P = pair<cost_t,int>; function<P(int,int)> dfs = [&](int p, int par) -> P{ P res = {0,p}; for(auto&& e : g[p]) { if(e.to == par or erased[e.to]) continue; auto v = dfs(e.to,p); v.first += e.cost; res = max(res,v); } return res; }; int r = -100; REP(i,SZ(erased)) if(!erased[i]){ r = i; break; } auto ap1 = dfs(0,-1); auto ap2 = dfs(ap1.second,-1); return make_tuple(ap2.first,ap2.second,ap1.second); } pair<int,int> getTreeCenter(const Graph& g){ cost_t di; int x, y; tie(di, x, y) = getTreeDiameter(g, erased); DEBUG(di); pair<int,int> res(-1,-1); cost_t mi; function<cost_t(int,int)> rec = [&](int p, int par) -> cost_t{ if(p == y){ return 0; } cost_t ress = -1; for(auto&& e : g[p]) if(e.to != par and !erased[e.to]){ cost_t v = rec(e.to,p); if(v != -1){ v += e.cost; ress = v; v = max(v, di-(v)); if(mi > v){ mi = v; res = {p,-1}; }else if(mi == v){ res.second = p; } } } return ress; }; rec(x,-1); return res; } void ios_init(){ //cout.setf(ios::fixed); //cout.precision(12); #ifdef LOCAL111 return; #endif ios::sync_with_stdio(false); cin.tie(0); } int main() { ios_init(); int n, k; while(cin >> n >> k) { Graph g(n); REP(i,n-1){ int a,b; cin >> a >> b; a--; b--; g.add_uedge(a,b,1); } int di; tie(di,ignore, ignore) = getTreeDiameter(g); int ans = 0; int r = (di+1)/2-k; while(true){ P c; c = getTreeCenter(g); vector<bool> used(n,false); function<void(int,int)> dfs = [&](int p, int d){ used[p] = true; if(d >= r){ ans++; } for(auto&& e : g[p]) if(!used[e.to]){ dfs(e.to,d+1); } }; dfs(c.F,0); fill(ALL(used),false); if(c.S != -1) dfs(c.S,0); } cout << ans << endl; } return 0; }
a.cc: In lambda function: a.cc:253:43: error: 'erased' was not declared in this scope 253 | if(e.to == par or erased[e.to]) continue; | ^~~~~~ a.cc: In function 'std::tuple<long long int, int, int> getTreeDiameter(const Graph&)': a.cc:262:18: error: 'erased' was not declared in this scope 262 | REP(i,SZ(erased)) if(!erased[i]){ | ^~~~~~ a.cc:223:37: note: in definition of macro 'FOR' 223 | #define FOR(i,a,b) for(int i=(a);i<(b);++i) | ^ a.cc:262:9: note: in expansion of macro 'REP' 262 | REP(i,SZ(erased)) if(!erased[i]){ | ^~~ a.cc:262:15: note: in expansion of macro 'SZ' 262 | REP(i,SZ(erased)) if(!erased[i]){ | ^~ a.cc: In function 'std::pair<int, int> getTreeCenter(const Graph&)': a.cc:274:44: error: 'erased' was not declared in this scope 274 | tie(di, x, y) = getTreeDiameter(g, erased); | ^~~~~~
s472407233
p04049
C++
#include <bits/stdc++.h> #define N 2002 #define PB push_back #define MP make_pair #define F first #define S second using namespace std; int n, m, k, i, j, l, r, t, fix[N], fox[N], a[N][N], d, ans; vector<int>v[N]; queue<int>q; int main() { cin>>n>>k; if(k==1){ cout<n-2<<endl; return 0; } for(i=0;i<n-1;i++){ cin>>l>>r; v[r].PB(l); v[l].PB(r); } for(i=1;i<=n;i++){ for(j=1;j<=n;j++)fix[j]=-1; fix[i]=0; q.push(i); while(q.size()){ t=q.front(); q.pop(); d=max(d,a[i][t]); for(j=0;j<v[t].size();j++){ if(fix[v[t][j]]!=-1)continue; q.push(v[t][j]); a[i][v[t][j]]=fix[v[t][j]]=a[i][t]+1; } } } //for(i=1;i<=n;i++){for(j=1;j<=n;j++)cout<<a[i][j]<<" ";cout<<endl;} if(k>=d){cout<<0<<endl;return 0;} if(k%2==1){ m=1; for(j=1;j<=n;j++){ if(a[i][j]==k/2){ if(m<v[j].size())m=v[j].size(); } } m--; } for(i=1;i<=n;i++){ t=0; for(j=1;j<=n;j++){ if(a[i][j]<=k/2)t++; } if(k%2==1)t+=m; ans=max(ans,t); } ans=n-ans; cout<<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:14:17: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<' 14 | cout<n-2<<endl; | ~~~^~~~~~
s465743046
p04049
Java
import java.util.*; public class Main { private final Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); private final Map<Long, List<Long>> edges = new HashMap<Long, List<Long>>(); private final int N, K; Diameter(String input) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); N = Integer.parseInt(NandK[0]); K = Integer.parseInt(NandK[1]); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!edges.containsKey(fromVindex)) edges.put(fromVindex, new ArrayList<Long>()); if (!edges.containsKey(toVindex)) edges.put(toVindex, new ArrayList<Long>()); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); edges.get(fromVindex).add(toVindex); edges.get(toVindex).add(fromVindex); } } private class Vertex { final long vindex; Vertex(long vindex) { this.vindex = vindex; } List<Long> getNeighbours(Long exceptVertext) { List<Long> result = new ArrayList<Long>(edges.get(vindex)); result.remove(exceptVertext); return result; } public String toString() { return Long.toString(vindex); } public int countVerticesAround(int D) { if (D == 0) return 1; if (D == 1) return Math.min(vertices.size(), 2); int R = D / 2; int resultForD = recursiveCount(R, null); if (D % 2 == 1) { int maxExtra = 0; for (long n : getNeighbours(null)) { int currExtra = vertices.get(n).recursiveCountAt(R, 0, vindex); maxExtra = Math.max(currExtra, maxExtra); } resultForD += maxExtra; } return resultForD ; } private int recursiveCount(long maxR, Long from) { List<Long> ns = getNeighbours(from); if (maxR == 0) return 1; int result = 1; for (Long n : ns) result += vertices.get(n).recursiveCount(maxR - 1, vindex); return result; } private int recursiveCountAt(final long max, long curr, Long from) { int result = 0; if (curr == max) return 1; for (Long n : getNeighbours(from)) result += vertices.get(n).recursiveCountAt(max, curr + 1, vindex); return result; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n-1;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } new Main(sampleInput).solve(); } public int solve() { int result = Integer.MAX_VALUE; for (Vertex vertex : vertices.values()) { int numVerticesToRatain = vertex.countVerticesAround(K); result = Math.min(result, vertices.size() - numVerticesToRatain); } System.out.println(result); return result; } }
Main.java:9: error: invalid method declaration; return type required Diameter(String input) ^ 1 error
s987755960
p04049
Java
import java.util.*; public class Main { private final Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); private final Map<Long, List<Long>> edges = new HashMap<Long, List<Long>>(); private final int N, K; Diameter(String input) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); N = Integer.parseInt(NandK[0]); K = Integer.parseInt(NandK[1]); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!edges.containsKey(fromVindex)) edges.put(fromVindex, new ArrayList<Long>()); if (!edges.containsKey(toVindex)) edges.put(toVindex, new ArrayList<Long>()); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); edges.get(fromVindex).add(toVindex); edges.get(toVindex).add(fromVindex); } } private class Vertex { final long vindex; Vertex(long vindex) { this.vindex = vindex; } List<Long> getNeighbours(Long exceptVertext) { List<Long> result = new ArrayList<Long>(edges.get(vindex)); result.remove(exceptVertext); return result; } public String toString() { return Long.toString(vindex); } public int countVerticesAround(int D) { if (D == 0) return 1; if (D == 1) return Math.min(vertices.size(), 2); int R = D / 2; int resultForD = recursiveCount(R, null); if (D % 2 == 1) { int maxExtra = 0; for (long n : getNeighbours(null)) { int currExtra = vertices.get(n).recursiveCountAt(R, 0, vindex); maxExtra = Math.max(currExtra, maxExtra); } resultForD += maxExtra; } return resultForD ; } private int recursiveCount(long maxR, Long from) { List<Long> ns = getNeighbours(from); if (maxR == 0) return 1; int result = 1; for (Long n : ns) result += vertices.get(n).recursiveCount(maxR - 1, vindex); return result; } private int recursiveCountAt(final long max, long curr, Long from) { int result = 0; if (curr == max) return 1; for (Long n : getNeighbours(from)) result += vertices.get(n).recursiveCountAt(max, curr + 1, vindex); return result; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n-1;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } new Diameter(sampleInput).solve(); } public int solve() { int result = Integer.MAX_VALUE; for (Vertex vertex : vertices.values()) { int numVerticesToRatain = vertex.countVerticesAround(K); result = Math.min(result, vertices.size() - numVerticesToRatain); } System.out.println(result); return result; } }
Main.java:9: error: invalid method declaration; return type required Diameter(String input) ^ 1 error
s182527784
p04049
Java
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; import java.lang.*; import java.util.Iterator; public class Main { private static class Edge { Vertex from, to; long fromDepth, toDepth; long fromCost, toCost; public Edge(Vertex from, Vertex to) { this.from = from; this.to = to; this.from.edges.add(this); this.to.edges.add(this); } void setFrom(Vertex newFrom) { // Swap if needed if (newFrom == to) { Vertex tmp = this.from; this.from = to; to = tmp; } else if (newFrom != from) throw new RuntimeException("Abracadabra froms do not agree"); } } private static class GraphTraversalData { final long maxDepthFromThisVertex, maxCostFromThisVertex; GraphTraversalData(long maxDepthFromThisVertex, long maxCostFromThisVertex) { this.maxDepthFromThisVertex = maxDepthFromThisVertex; this.maxCostFromThisVertex = maxCostFromThisVertex; } } private static class Vertex { final long vindex; List<Edge> edges = new ArrayList<Edge>(); Vertex(long vindex) { this.vindex = vindex; } public String toString() { return Long.toString(vindex); } public void populateData() { // First pass to figure out the out/to direction for (Edge edge : edges) { edge.setFrom(this); edge.to.traverseGraphAndSetToData(edge); } // Second pass to figure out the in/from direction traverseGraphAndSetFromData(null); } void traverseGraphAndSetFromData(Edge arrivedVia) { long totalCostViaOtherEdges, maxDViaOtherEdges; for (Edge edge : edges) { if (edge != arrivedVia) { totalCostViaOtherEdges = 0; maxDViaOtherEdges = 0; for (Edge tmpEdge : edges) { if (tmpEdge != edge && tmpEdge != arrivedVia) { totalCostViaOtherEdges += tmpEdge.toCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, tmpEdge.toDepth); } } if (arrivedVia != null) { totalCostViaOtherEdges += arrivedVia.fromCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, arrivedVia.fromDepth); } edge.fromCost = totalCostViaOtherEdges + 1; edge.fromDepth = maxDViaOtherEdges + 1; edge.to.traverseGraphAndSetFromData(edge); } } } private GraphTraversalData traverseGraphAndSetToData(Edge arrivedVia) { long maxDepthFromThisVertex = 0; long maxCostFromThisVertex = 1; for (Edge edge : edges) { if (edge != arrivedVia) { edge.setFrom(this); GraphTraversalData graphTraversalData = edge.to.traverseGraphAndSetToData(edge); maxCostFromThisVertex += graphTraversalData.maxCostFromThisVertex; maxDepthFromThisVertex = Math.max(maxDepthFromThisVertex, graphTraversalData.maxDepthFromThisVertex); } } arrivedVia.toDepth = maxDepthFromThisVertex + 1; arrivedVia.toCost = maxCostFromThisVertex; return new GraphTraversalData(arrivedVia.toDepth, maxCostFromThisVertex); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n-1;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } solve(sampleInput, false); } private static int solve(String input, boolean testMode) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); //System.out.println("N is " + NandK[0] + ", K is " + NandK[1]); long N = Long.parseLong(NandK[0]); long K = Long.parseLong(NandK[1]); Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); List<Edge> edges = new ArrayList<Edge>(); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); Vertex fromVertex = vertices.get(fromVindex); Vertex toVertex = vertices.get(toVindex); edges.add(new Edge(fromVertex, toVertex)); } if (testMode) { for (Vertex vertex : vertices.values()) { vertex.populateData(); long result = solveForK(edges, K); System.out.println("Result is " + result); } } else { Iterator<Vertex> viteratpr = vertices.values().iterator(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext(); Vertex vertex = viteratpr.next(); vertex.populateData(); System.out.println(result); } return 0; } static long solveForK(List<Edge> edges, long K) { long minRemovedVertices = Long.MAX_VALUE; for (Edge edge : edges) { if (edge.fromDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.toCost - 1); if (edge.toDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.fromCost - 1); } return minRemovedVertices == Long.MAX_VALUE ? 0 : minRemovedVertices; } }
Main.java:196: error: cannot find symbol System.out.println(result); ^ symbol: variable result location: class Main 1 error
s642759520
p04049
Java
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Iterator; public class Main { private static class Edge { Vertex from, to; long fromDepth, toDepth; long fromCost, toCost; public Edge(Vertex from, Vertex to) { this.from = from; this.to = to; this.from.edges.add(this); this.to.edges.add(this); } void setFrom(Vertex newFrom) { // Swap if needed if (newFrom == to) { Vertex tmp = this.from; this.from = to; to = tmp; } else if (newFrom != from) throw new RuntimeException("Abracadabra froms do not agree"); } } private static class GraphTraversalData { final long maxDepthFromThisVertex, maxCostFromThisVertex; GraphTraversalData(long maxDepthFromThisVertex, long maxCostFromThisVertex) { this.maxDepthFromThisVertex = maxDepthFromThisVertex; this.maxCostFromThisVertex = maxCostFromThisVertex; } } private static class Vertex { final long vindex; List<Edge> edges = new ArrayList<Edge>(); Vertex(long vindex) { this.vindex = vindex; } public String toString() { return Long.toString(vindex); } public void populateData() { // First pass to figure out the out/to direction for (Edge edge : edges) { edge.setFrom(this); edge.to.traverseGraphAndSetToData(edge); } // Second pass to figure out the in/from direction traverseGraphAndSetFromData(null); } void traverseGraphAndSetFromData(Edge arrivedVia) { long totalCostViaOtherEdges, maxDViaOtherEdges; for (Edge edge : edges) { if (edge != arrivedVia) { totalCostViaOtherEdges = 0; maxDViaOtherEdges = 0; for (Edge tmpEdge : edges) { if (tmpEdge != edge && tmpEdge != arrivedVia) { totalCostViaOtherEdges += tmpEdge.toCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, tmpEdge.toDepth); } } if (arrivedVia != null) { totalCostViaOtherEdges += arrivedVia.fromCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, arrivedVia.fromDepth); } edge.fromCost = totalCostViaOtherEdges + 1; edge.fromDepth = maxDViaOtherEdges + 1; edge.to.traverseGraphAndSetFromData(edge); } } } private GraphTraversalData traverseGraphAndSetToData(Edge arrivedVia) { long maxDepthFromThisVertex = 0; long maxCostFromThisVertex = 1; for (Edge edge : edges) { if (edge != arrivedVia) { edge.setFrom(this); GraphTraversalData graphTraversalData = edge.to.traverseGraphAndSetToData(edge); maxCostFromThisVertex += graphTraversalData.maxCostFromThisVertex; maxDepthFromThisVertex = Math.max(maxDepthFromThisVertex, graphTraversalData.maxDepthFromThisVertex); } } arrivedVia.toDepth = maxDepthFromThisVertex + 1; arrivedVia.toCost = maxCostFromThisVertex; return new GraphTraversalData(arrivedVia.toDepth, maxCostFromThisVertex); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n-1;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } solve(sampleInput, false); } private static int solve(String input, boolean testMode) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); //System.out.println("N is " + NandK[0] + ", K is " + NandK[1]); long N = Long.parseLong(NandK[0]); long K = Long.parseLong(NandK[1]); Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); List<Edge> edges = new ArrayList<Edge>(); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); Vertex fromVertex = vertices.get(fromVindex); Vertex toVertex = vertices.get(toVindex); edges.add(new Edge(fromVertex, toVertex)); } if (testMode) { for (Vertex vertex : vertices.values()) { vertex.populateData(); long result = solveForK(edges, K); System.out.println("Result is " + result); } } else { Iterator<Vertex> viteratpr = vertices.values().iterator(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext(); Vertex vertex = viteratpr.next(); vertex.populateData(); System.out.println(result); } return 0; } static long solveForK(List<Edge> edges, long K) { long minRemovedVertices = Long.MAX_VALUE; for (Edge edge : edges) { if (edge.fromDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.toCost - 1); if (edge.toDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.fromCost - 1); } return minRemovedVertices == Long.MAX_VALUE ? 0 : minRemovedVertices; } }
Main.java:196: error: cannot find symbol System.out.println(result); ^ symbol: variable result location: class Main 1 error
s863936723
p04049
Java
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Iterator; public class Main { private static class Edge { Vertex from, to; long fromDepth, toDepth; long fromCost, toCost; public Edge(Vertex from, Vertex to) { this.from = from; this.to = to; this.from.edges.add(this); this.to.edges.add(this); } void setFrom(Vertex newFrom) { // Swap if needed if (newFrom == to) { Vertex tmp = this.from; this.from = to; to = tmp; } else if (newFrom != from) throw new RuntimeException("Abracadabra froms do not agree"); } } private static class GraphTraversalData { final long maxDepthFromThisVertex, maxCostFromThisVertex; GraphTraversalData(long maxDepthFromThisVertex, long maxCostFromThisVertex) { this.maxDepthFromThisVertex = maxDepthFromThisVertex; this.maxCostFromThisVertex = maxCostFromThisVertex; } } private static class Vertex { final long vindex; List<Edge> edges = new ArrayList<Edge>(); Vertex(long vindex) { this.vindex = vindex; } public String toString() { return Long.toString(vindex); } public void populateData() { // First pass to figure out the out/to direction for (Edge edge : edges) { edge.setFrom(this); edge.to.traverseGraphAndSetToData(edge); } // Second pass to figure out the in/from direction traverseGraphAndSetFromData(null); } void traverseGraphAndSetFromData(Edge arrivedVia) { long totalCostViaOtherEdges, maxDViaOtherEdges; for (Edge edge : edges) { if (edge != arrivedVia) { totalCostViaOtherEdges = 0; maxDViaOtherEdges = 0; for (Edge tmpEdge : edges) { if (tmpEdge != edge && tmpEdge != arrivedVia) { totalCostViaOtherEdges += tmpEdge.toCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, tmpEdge.toDepth); } } if (arrivedVia != null) { totalCostViaOtherEdges += arrivedVia.fromCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, arrivedVia.fromDepth); } edge.fromCost = totalCostViaOtherEdges + 1; edge.fromDepth = maxDViaOtherEdges + 1; edge.to.traverseGraphAndSetFromData(edge); } } } private GraphTraversalData traverseGraphAndSetToData(Edge arrivedVia) { long maxDepthFromThisVertex = 0; long maxCostFromThisVertex = 1; for (Edge edge : edges) { if (edge != arrivedVia) { edge.setFrom(this); GraphTraversalData graphTraversalData = edge.to.traverseGraphAndSetToData(edge); maxCostFromThisVertex += graphTraversalData.maxCostFromThisVertex; maxDepthFromThisVertex = Math.max(maxDepthFromThisVertex, graphTraversalData.maxDepthFromThisVertex); } } arrivedVia.toDepth = maxDepthFromThisVertex + 1; arrivedVia.toCost = maxCostFromThisVertex; return new GraphTraversalData(arrivedVia.toDepth, maxCostFromThisVertex); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n-1;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } solve(sampleInput, false); } private static int solve(String input, boolean testMode) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); //System.out.println("N is " + NandK[0] + ", K is " + NandK[1]); long N = Long.parseLong(NandK[0]); long K = Long.parseLong(NandK[1]); Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); List<Edge> edges = new ArrayList<Edge>(); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); Vertex fromVertex = vertices.get(fromVindex); Vertex toVertex = vertices.get(toVindex); edges.add(new Edge(fromVertex, toVertex)); } if (testMode) { for (Vertex vertex : vertices.values()) { vertex.populateData(); long result = solveForK(edges, K); System.out.println("Result is " + result); } } else { Iterator<Vertex> viteratpr = vertices.values().iterator(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext(); Vertex vertex = viteratpr.next(); vertex.populateData(); System.out.println(result); } return 0; } static long solveForK(List<Edge> edges, long K) { long minRemovedVertices = Long.MAX_VALUE; for (Edge edge : edges) { if (edge.fromDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.toCost - 1); if (edge.toDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.fromCost - 1); } return minRemovedVertices == Long.MAX_VALUE ? 0 : minRemovedVertices; } }
Main.java:132: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class Main Main.java:132: error: cannot find symbol Scanner sc = new Scanner(System.in); ^ symbol: class Scanner location: class Main Main.java:194: error: cannot find symbol System.out.println(result); ^ symbol: variable result location: class Main 3 errors
s379961036
p04049
Java
import java.util.*; public class Main { private static class Edge { Vertex from, to; long fromDepth, toDepth; long fromCost, toCost; public Edge(Vertex from, Vertex to) { this.from = from; this.to = to; this.from.edges.add(this); this.to.edges.add(this); } void setFrom(Vertex newFrom) { // Swap if needed if (newFrom == to) { Vertex tmp = this.from; this.from = to; to = tmp; } else if (newFrom != from) throw new RuntimeException("Abracadabra froms do not agree"); } } private static class GraphTraversalData { final long maxDepthFromThisVertex, maxCostFromThisVertex; GraphTraversalData(long maxDepthFromThisVertex, long maxCostFromThisVertex) { this.maxDepthFromThisVertex = maxDepthFromThisVertex; this.maxCostFromThisVertex = maxCostFromThisVertex; } } private static class Vertex { final long vindex; List<Edge> edges = new ArrayList<Edge>(); Vertex(long vindex) { this.vindex = vindex; } public String toString() { return Long.toString(vindex); } public void populateData() { // First pass to figure out the out/to direction for (Edge edge : edges) { edge.setFrom(this); edge.to.traverseGraphAndSetToData(edge); } // Second pass to figure out the in/from direction traverseGraphAndSetFromData(null); } void traverseGraphAndSetFromData(Edge arrivedVia) { long totalCostViaOtherEdges, maxDViaOtherEdges; for (Edge edge : edges) { if (edge != arrivedVia) { totalCostViaOtherEdges = 0; maxDViaOtherEdges = 0; for (Edge tmpEdge : edges) { if (tmpEdge != edge && tmpEdge != arrivedVia) { totalCostViaOtherEdges += tmpEdge.toCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, tmpEdge.toDepth); } } if (arrivedVia != null) { totalCostViaOtherEdges += arrivedVia.fromCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, arrivedVia.fromDepth); } edge.fromCost = totalCostViaOtherEdges + 1; edge.fromDepth = maxDViaOtherEdges + 1; edge.to.traverseGraphAndSetFromData(edge); } } } private GraphTraversalData traverseGraphAndSetToData(Edge arrivedVia) { long maxDepthFromThisVertex = 0; long maxCostFromThisVertex = 1; for (Edge edge : edges) { if (edge != arrivedVia) { edge.setFrom(this); GraphTraversalData graphTraversalData = edge.to.traverseGraphAndSetToData(edge); maxCostFromThisVertex += graphTraversalData.maxCostFromThisVertex; maxDepthFromThisVertex = Math.max(maxDepthFromThisVertex, graphTraversalData.maxDepthFromThisVertex); } } arrivedVia.toDepth = maxDepthFromThisVertex + 1; arrivedVia.toCost = maxCostFromThisVertex; return new GraphTraversalData(arrivedVia.toDepth, maxCostFromThisVertex); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n-1;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } solve(sampleInput, false); } private static int solve(String input, boolean testMode) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); //System.out.println("N is " + NandK[0] + ", K is " + NandK[1]); long N = Long.parseLong(NandK[0]); long K = Long.parseLong(NandK[1]); Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); List<Edge> edges = new ArrayList<Edge>(); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); Vertex fromVertex = vertices.get(fromVindex); Vertex toVertex = vertices.get(toVindex); edges.add(new Edge(fromVertex, toVertex)); } if (testMode) { for (Vertex vertex : vertices.values()) { vertex.populateData(); long result = solveForK(edges, K); System.out.println("Result is " + result); } } else { Iterator<Vertex> viteratpr = vertices.values().iterator(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext();viteratpr.next(); viteratpr.hasNext(); Vertex vertex = viteratpr.next(); vertex.populateData(); System.out.println(result); } return 0; } static long solveForK(List<Edge> edges, long K) { long minRemovedVertices = Long.MAX_VALUE; for (Edge edge : edges) { if (edge.fromDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.toCost - 1); if (edge.toDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.fromCost - 1); } return minRemovedVertices == Long.MAX_VALUE ? 0 : minRemovedVertices; } }
Main.java:190: error: cannot find symbol System.out.println(result); ^ symbol: variable result location: class Main 1 error
s575248021
p04049
Java
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; public class Main { private static class Edge { Vertex from, to; long fromDepth, toDepth; long fromCost, toCost; public Edge(Vertex from, Vertex to) { this.from = from; this.to = to; this.from.edges.add(this); this.to.edges.add(this); } void setFrom(Vertex newFrom) { // Swap if needed if (newFrom == to) { Vertex tmp = this.from; this.from = to; to = tmp; } else if (newFrom != from) throw new RuntimeException("Abracadabra froms do not agree"); } } private static class GraphTraversalData { final long maxDepthFromThisVertex, maxCostFromThisVertex; GraphTraversalData(long maxDepthFromThisVertex, long maxCostFromThisVertex) { this.maxDepthFromThisVertex = maxDepthFromThisVertex; this.maxCostFromThisVertex = maxCostFromThisVertex; } } private static class Vertex { final long vindex; List<Edge> edges = new ArrayList<Edge>(); Vertex(long vindex) { this.vindex = vindex; } public String toString() { return Long.toString(vindex); } public void populateData() { // First pass to figure out the out/to direction for (Edge edge : edges) { edge.setFrom(this); edge.to.traverseGraphAndSetToData(edge); } // Second pass to figure out the in/from direction traverseGraphAndSetFromData(null); } void traverseGraphAndSetFromData(Edge arrivedVia) { long totalCostViaOtherEdges, maxDViaOtherEdges; for (Edge edge : edges) { if (edge != arrivedVia) { totalCostViaOtherEdges = 0; maxDViaOtherEdges = 0; for (Edge tmpEdge : edges) { if (tmpEdge != edge && tmpEdge != arrivedVia) { totalCostViaOtherEdges += tmpEdge.toCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, tmpEdge.toDepth); } } if (arrivedVia != null) { totalCostViaOtherEdges += arrivedVia.fromCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, arrivedVia.fromDepth); } edge.fromCost = totalCostViaOtherEdges + 1; edge.fromDepth = maxDViaOtherEdges + 1; edge.to.traverseGraphAndSetFromData(edge); } } } private GraphTraversalData traverseGraphAndSetToData(Edge arrivedVia) { long maxDepthFromThisVertex = 0; long maxCostFromThisVertex = 1; for (Edge edge : edges) { if (edge != arrivedVia) { edge.setFrom(this); GraphTraversalData graphTraversalData = edge.to.traverseGraphAndSetToData(edge); maxCostFromThisVertex += graphTraversalData.maxCostFromThisVertex; maxDepthFromThisVertex = Math.max(maxDepthFromThisVertex, graphTraversalData.maxDepthFromThisVertex); } } arrivedVia.toDepth = maxDepthFromThisVertex + 1; arrivedVia.toCost = maxCostFromThisVertex; return new GraphTraversalData(arrivedVia.toDepth, maxCostFromThisVertex); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n-1;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } solve(sampleInput, false); } private static int solve(String input, boolean testMode) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); //System.out.println("N is " + NandK[0] + ", K is " + NandK[1]); long N = Long.parseLong(NandK[0]); long K = Long.parseLong(NandK[1]); Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); List<Edge> edges = new ArrayList<Edge>(); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); Vertex fromVertex = vertices.get(fromVindex); Vertex toVertex = vertices.get(toVindex); edges.add(new Edge(fromVertex, toVertex)); } if (testMode) { for (Vertex vertex : vertices.values()) { vertex.populateData(); long result = solveForK(edges, K); System.out.println("Result is " + result); } } else { Vertex vertex = vertices.values().iterator().next(); vertex.populateData(); long result = solveForK(edges, K); //System.out.println(result); throw new RuntimeException("test") } return 0; } static long solveForK(List<Edge> edges, long K) { long minRemovedVertices = Long.MAX_VALUE; for (Edge edge : edges) { if (edge.fromDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.toCost - 1); if (edge.toDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.fromCost - 1); } return minRemovedVertices == Long.MAX_VALUE ? 0 : minRemovedVertices; } }
Main.java:190: error: ';' expected throw new RuntimeException("test") ^ 1 error
s557775881
p04049
Java
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; public class Diameter { private static class Edge { Vertex from, to; long fromDepth, toDepth; long fromCost, toCost; public Edge(Vertex from, Vertex to) { this.from = from; this.to = to; this.from.edges.add(this); this.to.edges.add(this); } void setFrom(Vertex newFrom) { // Swap if needed if (newFrom == to) { Vertex tmp = this.from; this.from = to; to = tmp; } else if (newFrom != from) throw new RuntimeException("Abracadabra froms do not agree"); } } private static class GraphTraversalData { final long maxDepthFromThisVertex, maxCostFromThisVertex; GraphTraversalData(long maxDepthFromThisVertex, long maxCostFromThisVertex) { this.maxDepthFromThisVertex = maxDepthFromThisVertex; this.maxCostFromThisVertex = maxCostFromThisVertex; } } private static class Vertex { final long vindex; List<Edge> edges = new ArrayList<Edge>(); Vertex(long vindex) { this.vindex = vindex; } public String toString() { return Long.toString(vindex); } public void populateData() { // First pass to figure out the out/to direction for (Edge edge : edges) { edge.setFrom(this); edge.to.traverseGraphAndSetToData(edge); } // Second pass to figure out the in/from direction traverseGraphAndSetFromData(null); } void traverseGraphAndSetFromData(Edge arrivedVia) { long totalCostViaOtherEdges, maxDViaOtherEdges; for (Edge edge : edges) { if (edge != arrivedVia) { totalCostViaOtherEdges = 0; maxDViaOtherEdges = 0; for (Edge tmpEdge : edges) { if (tmpEdge != edge && tmpEdge != arrivedVia) { totalCostViaOtherEdges += tmpEdge.toCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, tmpEdge.toDepth); } } if (arrivedVia != null) { totalCostViaOtherEdges += arrivedVia.fromCost; maxDViaOtherEdges = Math.max(maxDViaOtherEdges, arrivedVia.fromDepth); } edge.fromCost = totalCostViaOtherEdges + 1; edge.fromDepth = maxDViaOtherEdges + 1; edge.to.traverseGraphAndSetFromData(edge); } } } private GraphTraversalData traverseGraphAndSetToData(Edge arrivedVia) { long maxDepthFromThisVertex = 0; long maxCostFromThisVertex = 1; for (Edge edge : edges) { if (edge != arrivedVia) { edge.setFrom(this); GraphTraversalData graphTraversalData = edge.to.traverseGraphAndSetToData(edge); maxCostFromThisVertex += graphTraversalData.maxCostFromThisVertex; maxDepthFromThisVertex = Math.max(maxDepthFromThisVertex, graphTraversalData.maxDepthFromThisVertex); } } arrivedVia.toDepth = maxDepthFromThisVertex + 1; arrivedVia.toCost = maxCostFromThisVertex; return new GraphTraversalData(arrivedVia.toDepth, maxCostFromThisVertex); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); String sampleInput = n + " " +d +"\n"; for (int i = 0; i<n;i++){ String a = sc.next(); String b= sc.next(); sampleInput = sampleInput + a+" "+b+"\n"; } solve(sampleInput, false); } private static int solve(String input, boolean testMode) { String[] lines = input.split("\n"); String[] NandK = lines[0].split(" "); System.out.println("N is " + NandK[0] + ", K is " + NandK[1]); long N = Long.parseLong(NandK[0]); long K = Long.parseLong(NandK[1]); Map<Long, Vertex> vertices = new HashMap<Long, Vertex>(); List<Edge> edges = new ArrayList<Edge>(); for (int i = 1; i < N; i++) { String[] edgeInfo = lines[i].split(" "); long fromVindex = Long.parseLong(edgeInfo[0]); long toVindex = Long.parseLong(edgeInfo[1]); if (!vertices.containsKey(fromVindex)) vertices.put(fromVindex, new Vertex(fromVindex)); if (!vertices.containsKey(toVindex)) vertices.put(toVindex, new Vertex(toVindex)); Vertex fromVertex = vertices.get(fromVindex); Vertex toVertex = vertices.get(toVindex); edges.add(new Edge(fromVertex, toVertex)); } if (testMode) { for (Vertex vertex : vertices.values()) { vertex.populateData(); long result = solveForK(edges, K); System.out.println("Result is " + result); } } else { Vertex vertex = vertices.values().iterator().next(); vertex.populateData(); long result = solveForK(edges, K); System.out.println(result); } return 0; } static long solveForK(List<Edge> edges, long K) { long minRemovedVertices = Long.MAX_VALUE; for (Edge edge : edges) { if (edge.fromDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.toCost - 1); if (edge.toDepth <= K) minRemovedVertices = Math.min(minRemovedVertices, edge.fromCost - 1); } return minRemovedVertices == Long.MAX_VALUE ? 0 : minRemovedVertices; } }
Main.java:7: error: class Diameter is public, should be declared in a file named Diameter.java public class Diameter ^ 1 error
s078468845
p04049
C++
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int NMAX = 2000 + 5; int n, k; int h[NMAX]; int sz[NMAX]; int dp[NMAX][NMAX]; //dp[node][h] = numarul minim de noduri care trebuie //eliminate pentru a obtine inaltimea maxim h in //subarborele lui node int dp2[NMAX][NMAX]; //dp[son][h] = numarul minim de noduri care trebuie //eliminate dintre nodurile de pana la fiul son //(exclusiv) astfel incat inaltimea maxima sa fie h, //iar diametrul sa nu depaseasca k vector <int> graph[NMAX]; void upd(int &where, int val) { if (val < where) where = val; } void dfs(int node, int father) { if (father) graph[node].erase(find(graph[node].begin(), graph[node].end(), father)); h[node] = 0; sz[node] = 1; for (auto it: graph[node]) { dfs(it, node); if (h[it] > h[node]) h[node] = h[it]; sz[node] += sz[it]; } ++ h[node]; int max_h = 0; for (int son = 0; son < static_cast <int>(graph[node].size()); ++ son) { for (int j = 0; j <= max(max_h, h[graph[node][son]]); ++ j) dp2[son + 1][j] = NMAX; for (int j = 0; j <= max_h && j <= k + 1; ++ j) { for (int l = 0; l <= h[graph[node][son]]; ++ l) { if (j + l <= k) upd(dp2[son + 1][max(j, l)], dp[graph[node][son]][l] + dp2[son][j]); } } max_h = max(max_h, h[graph[node][son]]); } dp[node][0] = sz[node]; for (int j = 0; j < h[node] && j <= K; ++ j) dp[node][j + 1] = dp2[graph[node].size()][j]; } int main() { cin >> n >> k; int a, b; for (int i = 1; i < n; ++ i) { cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } dfs(1, 0); int ans = NMAX; for (int root = 1; root <= n; ++ root) { int current = NMAX; for (int l = 0; l <= k + 1; ++ l) upd(current, dp[root][l]); upd(ans, n - sz[root] + current); } cout << ans << '\n'; return 0; }
a.cc: In function 'void dfs(int, int)': a.cc:60:41: error: 'K' was not declared in this scope 60 | for (int j = 0; j < h[node] && j <= K; ++ j) | ^
s768842945
p04049
C++
#include <bits/stdc++.h> using namespace std; vector<int> edges[2010]; int dist[2010][2010]; void dfs(int now, int fa, int depth,int root) { dist[root][now] = depth; for(int next: edges[now]) { if(next == fa) { continue; } dfs(next, now, depth + 1, root); } } void count() { int n, k; cin>>n>>k; vector<pair<int, int> > edgePairs; for(int i = 1; i < n; ++ i) { int u, v; cin<<u<<v; -- u, -- v; edges[u].push_back(v); edges[v].push_back(u); edgePairs.push_back(make_pair(u, v)); } for(int i = 0; i < n; ++ i) { dfs(i, i, 0, i); } int ans = 0; if(k & 1) { k >>= 1; for(auto edge: edgePairs) { int cnt = 0; for(int i = 0; i < n; ++ i) { cnt += min(dist[edge.first][i], dist[edge.second][i]) <= k; } ans = max(ans, cnt); } } else { k >>= 1; for(int root = 0; root < n; ++ root) { int cnt = 0; for(int i = 0; i < n; ++ i) { cnt += dist[root][i] <= k; } ans = max(ans, cnt); } } cout<<n-ans<<endl; } int main() { count(); return 0; }
a.cc: In function 'void count()': a.cc:23:16: error: no match for 'operator<<' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'int') 23 | cin<<u<<v; | ~~~^~~ | | | | | int | std::istream {aka std::basic_istream<char>} a.cc:23:16: note: candidate: 'operator<<(int, int)' (built-in) 23 | cin<<u<<v; | ~~~^~~ a.cc:23:16: note: no known conversion for argument 1 from 'std::istream' {aka 'std::basic_istream<char>'} to 'int' In file included from /usr/include/c++/14/regex:68, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181, from a.cc:1: /usr/include/c++/14/bits/regex.h:1715:5: note: candidate: 'template<class _Ch_type, class _Ch_traits, class _Bi_iter> std::basic_ostream<_CharT, _Traits>& std::__cxx11::operator<<(std::basic_ostream<_CharT, _Traits>&, const sub_match<_Bi_iter>&)' 1715 | operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1715:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:41: /usr/include/c++/14/cstddef:125:5: note: candidate: 'template<class _IntegerType> constexpr std::__byte_op_t<_IntegerType> std::operator<<(byte, _IntegerType)' 125 | operator<<(byte __b, _IntegerType __shift) noexcept | ^~~~~~~~ /usr/include/c++/14/cstddef:125:5: note: template argument deduction/substitution failed: a.cc:23:13: note: cannot convert 'std::cin' (type 'std::istream' {aka 'std::basic_istream<char>'}) to type 'std::byte' 23 | cin<<u<<v; | ^~~ In file included from /usr/include/c++/14/bits/basic_string.h:47, from /usr/include/c++/14/string:54, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52: /usr/include/c++/14/string_view:763:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, basic_string_view<_CharT, _Traits>)' 763 | operator<<(basic_ostream<_CharT, _Traits>& __os, | ^~~~~~~~ /usr/include/c++/14/string_view:763:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/bits/basic_string.h:4077:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 4077 | operator<<(basic_ostream<_CharT, _Traits>& __os, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:4077:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/bitset:1687:5: note: candidate: 'template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const bitset<_Nb>&)' 1687 | operator<<(std::basic_ostream<_CharT, _Traits>& __os, | ^~~~~~~~ /usr/include/c++/14/bitset:1687:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ In file included from /usr/include/c++/14/bits/ios_base.h:46, from /usr/include/c++/14/streambuf:43, from /usr/include/c++/14/bits/streambuf_iterator.h:35, from /usr/include/c++/14/iterator:66, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54: /usr/include/c++/14/system_error:339:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const error_code&)' 339 | operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e) | ^~~~~~~~ /usr/include/c++/14/system_error:339:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ In file included from /usr/include/c++/14/memory:80, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:56: /usr/include/c++/14/bits/shared_ptr.h:70:5: note: candidate: 'template<class _Ch, class _Tr, class _Tp, __gnu_cxx::_Lock_policy _Lp> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const __shared_ptr<_Tp, _Lp>&)' 70 | operator<<(std::basic_ostream<_Ch, _Tr>& __os, | ^~~~~~~~ /usr/include/c++/14/bits/shared_ptr.h:70:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ In file included from /usr/include/c++/14/istream:41, from /usr/include/c++/14/sstream:40, from /usr/include/c++/14/complex:45, from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127: /usr/include/c++/14/ostream:563:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, _CharT)' 563 | operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c) | ^~~~~~~~ /usr/include/c++/14/ostream:563:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/ostream:573:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char)' 573 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c) | ^~~~~~~~ /usr/include/c++/14/ostream:573:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/ostream:579:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char)' 579 | operator<<(basic_ostream<char, _Traits>& __out, char __c) | ^~~~~~~~ /usr/include/c++/14/ostream:579:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/ostream:590:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char)' 590 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c) | ^~~~~~~~ /usr/include/c++/14/ostream:590:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/ostream:595:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char)' 595 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c) | ^~~~~~~~ /usr/include/c++/14/ostream:595:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/ostream:654:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const _CharT*)' 654 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) | ^~~~~~~~ /usr/include/c++/14/ostream:654:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ In file included from /usr/include/c++/14/ostream:1022: /usr/include/c++/14/bits/ostream.tcc:307:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const char*)' 307 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) | ^~~~~~~~ /usr/include/c++/14/bits/ostream.tcc:307:5: note: template argument deduction/substitution failed: a.cc:23:18: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>' 23 | cin<<u<<v; | ^ /usr/include/c++/14/ostream:671:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const char*)' 671 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s) | ^~~~~~~~ /usr/include/c++/14/ostream:671:5: note: template argument deduction/substitution f
s638298814
p04049
C++
#include<iostream> #include<vector> #include<cstdio> #include<algorithm> using namespace std; vector<int> edge[2010]; int dis[2010]; bool used[2010]; int n, k; int main() { int a, b,ma=100000; cin >> n >> k; for (int i = 0; i < n - 1; i++) { scanf("%d %d", &a, &b); a--; b--; edge[a].push_back(b); edge[b].push_back(a); } if (k % 2 == 0) { for (int i = 0; i < n; i++) { evencalc(i, i, 0); ma = min(ma, dis[i]); for (int i = 0; i < n; i++)used[i] = false; } cout << ma << endl; } else { for (int i = 0; i < n; i++) { if (edge[i].empty())continue; for (int j = 0; j < edge[i].size; j++) { ma = min(ma, oddcalc(i, edge[i][j])); } } cout << ma << endl; } } void evencalc(int t, int s, int count) { int r; if (count > (int)k / 2)dis[s]++; if (edge[t].empty())return; for (int i = 0; i < edge[t].size() && !used[edge[t][i]]; i++) { r = edge[t][i]; used[edge[t][i]] = true; evencalc(r, s, count+1); } } int oddcalc(int t,int s) { used[t] = used[s] = true; evencalc(t, t, 0); evencalc(s, s, 0); return dis[t]+ dis[s]; }
a.cc: In function 'int main()': a.cc:22:25: error: 'evencalc' was not declared in this scope 22 | evencalc(i, i, 0); | ^~~~~~~~ a.cc:31:53: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?) 31 | for (int j = 0; j < edge[i].size; j++) { | ~~~~~~~~^~~~ | () a.cc:32:46: error: 'oddcalc' was not declared in this scope 32 | ma = min(ma, oddcalc(i, edge[i][j])); | ^~~~~~~
s237422931
p04049
C++
#include <bits/stdc++.h> #define endl '\n' #define Int long long #define Double long double #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define CLR(a, b) memset(a, b, sizeof a) #define debug(x) cerr << #x << " " << x << endl; #define MOD 1000000007 #define MAXN 2002 using namespace std; int n, k; int depth[2][MAXN]; int mark[MAXN]; vector<int> net[MAXN]; void dfs(int v, int d, int t) { mark[v] = 1; depth[t][d]++; for(int i = 0; i < SZ(net[v]); ++i) { if(!mark[net[v][i]]) dfs(net[v][i], d + 1, t); } } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n >> k; for(int i = 0; i < n-1; ++i) { int u, v; cin >> u >> v; u--, v--; net[u].push_back(v); net[v].push_back(u); } int ans = INT_MAX; if(k%2 == 0) { for(int i = 0; i < n; ++i) { CLR(mark, 0); //CLR(depth, 0); for(int i = 0; i < n; ++i) depth[0][i] = 0; dfs(i, 0, 0); int res = 0; for(int i = k/2 + 1; i < n; ++i) res += depth[0][i]; ans = min(res, ans); } } else { for(int i = 0; i < n; ++i) { for(int j = 0; j < SZ(net[i]); ++j) { CLR(mark, 0); //CLR(depth, 0); for(int i = 0; i < n; ++i) depth[0][i] = depth[1][i] = 0 mark[net[i][j]] = 1; dfs(i, 0, 0); mark[net[i][j]] = 0; mark[i] = 1; dfs(net[i][j], 0, 1); int a = 0; int b = 0; for(int i = k/2 + 2; i < n; ++i) { a += depth[0][i]; b += depth[1][i]; } int res = min(a + b + depth[0][k/2 + 1], a + b + depth[1][k/2 + 1]); ans = min(ans, res); } } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:62:50: error: expected ';' before 'mark' 62 | depth[0][i] = depth[1][i] = 0 | ^ | ; 63 | 64 | mark[net[i][j]] = 1; | ~~~~
s329967213
p04049
C++
#include <bits/stdc++.h> #define endl '\n' #define Int long long #define Double long double #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define CLR(a, b) memset(a, b, sizeof a) #define debug(x) cerr << #x << " " << x << endl; #define MOD 1000000007 #define MAXN 2002 using namespace std; int n, k; int depth[2][MAXN]; int mark[MAXN]; vector<int> net[MAXN]; void dfs(int v, int d, int t) { mark[v] = 1; depth[t][d]++; for(int i = 0; i < SZ(net[v]); ++i) { if(!mark[net[v][i]]) dfs(net[v][i], d + 1, t); } } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n >> k; for(int i = 0; i < n-1; ++i) { int u, v; cin >> u >> v; u--, v--; net[u].push_back(v); net[v].push_back(u); } int ans = INT_MAX; if(k%2 == 0) { for(int i = 0; i < n; ++i) { CLR(mark, 0); //CLR(depth, 0); for(int i = 0; i < n; ++i) depth[0][i] = 0 dfs(i, 0, 0); int res = 0; for(int i = k/2 + 1; i < n; ++i) res += depth[0][i]; ans = min(res, ans); } } else { for(int i = 0; i < n; ++i) { for(int j = 0; j < SZ(net[i]); ++j) { CLR(mark, 0); //CLR(depth, 0); for(int i = 0; i < n; ++i) depth[0][i] = depth[1][i] = 0 mark[net[i][j]] = 1; dfs(i, 0, 0); mark[net[i][j]] = 0; mark[i] = 1; dfs(net[i][j], 0, 1); int a = 0; int b = 0; for(int i = k/2 + 2; i < n; ++i) { a += depth[0][i]; b += depth[1][i]; } int res = min(a + b + depth[0][k/2 + 1], a + b + depth[1][k/2 + 1]); ans = min(ans, res); } } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:47:32: error: expected ';' before 'dfs' 47 | depth[0][i] = 0 | ^ | ; 48 | 49 | dfs(i, 0, 0); | ~~~ a.cc:62:50: error: expected ';' before 'mark' 62 | depth[0][i] = depth[1][i] = 0 | ^ | ; 63 | 64 | mark[net[i][j]] = 1; | ~~~~
s161444394
p04049
C++
#include <algorithm> #include <map> #include <vector> #include <iostream> #include <stdio.h> #include <set> #include <string.h> typedef long long ll; using namespace std; int dfs(int me, vector<int> &visited, vector<vector<int> > &table, int left) { if (left<0) return 0; if (visited[me]==1) return 0; int ret=0; visited[me]=1; if (left==0) return table[me].size()-1; for (int i=0; i<table[me].size(); i++) ret=max(ret, dfs(table[me][i], visited, table, left-1)); return ret; } int main() { std::ios::sync_with_stdio(false); int n, k; cin>>n>>k; vector<vector<int> > table(n); for (int i=0; i<n-1; i++) { int tmp1, tmp2; cin>>tmp1>>tmp2; table[tmp1-1].push_back(tmp2-1); table[tmp2-1].push_back(tmp1-1); } int ans=n; for (int i=0; i<n; i++) { vector<int> visited(n, 0); visited[i]=1; int rem=0; for (int j=0; j<table[i].size(); j++) rem=max(rem, dfs(table[i][j], visited, table, k/2-1)); if (k==1) rem=1; int tmp=0; for (int j=0; j<n; j++) if (visite[j]==0) tmp++; if (k%2==1) ans=min(ans, tmp-rem); else ans=min(ans, tmp-rem); } cout<<ans; return 0; }
a.cc: In function 'int main()': a.cc:45:48: error: 'visite' was not declared in this scope; did you mean 'visited'? 45 | int tmp=0; for (int j=0; j<n; j++) if (visite[j]==0) tmp++; | ^~~~~~ | visited
s338628903
p04049
Java
package AGC001; import java.util.ArrayDeque; import java.util.ArrayList; \import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { solver(); } static void solver() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt();// modify the graphs to the one whose diameter is // equal or shorter than k. ArrayList<Integer>[] e = new ArrayList[n]; for (int i = 0; i < n; i++) { e[i] = new ArrayList<Integer>(); } for (int i = 0; i < n - 1; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; e[a].add(b); e[b].add(a); } depth = new int[n]; if (k % 2 == 0) { int ans = Integer.MAX_VALUE / 4; for (int i = 0; i < n; i++) { Arrays.fill(depth, 0); bfs(i, -1, 0, e); int count = 0; for (int j = 0; j < n; j++) { if (depth[j] > k / 2) count++; } ans = Math.min(ans, count); } System.out.println(ans); } else if (k % 2 == 1) { int ans = Integer.MAX_VALUE / 4; for (int i = 0; i < n; i++) { Arrays.fill(depth, 0); bfs(i, -1, 0, e); int[] depth1 = Arrays.copyOf(depth, depth.length); for (int v : e[i]) { Arrays.fill(depth, 0); bfs(v, -1, 0, e); int[] depth2 = Arrays.copyOf(depth, depth.length); int count = 0; for (int j = 0; j < n; j++) { if (depth1[j] > k / 2 && depth2[j] > k / 2) { count++; } } ans = Math.min(ans, count); } } System.out.println(ans); } } static int[] depth; static void bfs(int v, int p, int d, ArrayList<Integer>[] e) { ArrayDeque<P> q = new ArrayDeque<P>(); q.add(new P(v, p, d)); while (!q.isEmpty()) { P u = q.poll(); depth[u.me] = u.depth; for (int i = 0; i < e[u.me].size(); i++) { if (e[u.me].get(i) != u.parent) q.add(new P(e[u.me].get(i), u.me, u.depth + 1)); } } } static class P { int parent; int me; int depth; P(int me, int parent, int depth) { this.me = me; this.parent = parent; this.depth = depth; } } }
Main.java:5: error: illegal character: '\' \import java.util.Arrays; ^ Main.java:5: error: class, interface, enum, or record expected \import java.util.Arrays; ^ Main.java:6: error: class, interface, enum, or record expected import java.util.Scanner; ^ 3 errors
s817723224
p04049
C++
x
a.cc:1:1: error: 'x' does not name a type 1 | x | ^
s625552395
p04049
C++
#include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <ctime> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <iostream> #include <algorithm> #include <functional> #include <numeric> #include <string> using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define pb push_back #define mp make_pair #define all(a) (a).begin(),(a).end() #define debug(x) cout<<#x<<": "<<x<<endl #define MOD 1000000007 typedef long long ll; typedef unsigned long long ull; template <class T, class U> amax(T& x, U y) {if (x < y) x = y;} template <class T, class U> amin(T& x, U y) {if (x > y) x = y;} const int MAX_N = 2000; int main(void) { int N, K; cin >> N >> K; vector<int> g[MAX_N]; REP(i, N - 1) { int A, B; cin >> A >> B; A--; B--; g[A].pb(B); g[B].pb(A); } int ret = MAX_N; if (K % 2 == 0) { REP(v, N) { int d[MAX_N]; fill(d, d + N, MAX_N); queue<int> q; q.push(v); d[v] = 0; while (!q.empty()) { int u = q.front(); q.pop(); if (d[u] == K) { continue; } REP(i, g[u].size()) { int to = g[u][i]; if (d[to] > d[u] + 1) { d[to] = d[u] + 1; q.push(to); } } } int n_remove = 0; REP(i, N) { if (d[i] > K / 2) { n_remove++; } } ret = min(ret, n_remove); } } else { REP(v, N) REP (j, g[v].size()) { int u = g[v][j]; int d[MAX_N]; fill(d, d + N, MAX_N); queue<int> q; q.push(v); q.push(u); d[v] = 0; d[u] = 0; while (!q.empty()) { int u = q.front(); q.pop(); if (d[u] == K) { continue; } REP(i, g[u].size()) { int to = g[u][i]; if (d[to] > d[u] + 1) { d[to] = d[u] + 1; q.push(to); } } } int n_remove = 0; REP(i, N) { if (d[i] > K / 2) { n_remove++; } } ret = min(ret, n_remove); } } cout << ret << endl; return 0; }
a.cc:33:29: error: ISO C++ forbids declaration of 'amax' with no type [-fpermissive] 33 | template <class T, class U> amax(T& x, U y) {if (x < y) x = y;} | ^~~~ a.cc: In function 'int amax(T&, U)': a.cc:33:63: warning: no return statement in function returning non-void [-Wreturn-type] 33 | template <class T, class U> amax(T& x, U y) {if (x < y) x = y;} | ^ a.cc: At global scope: a.cc:34:29: error: ISO C++ forbids declaration of 'amin' with no type [-fpermissive] 34 | template <class T, class U> amin(T& x, U y) {if (x > y) x = y;} | ^~~~ a.cc: In function 'int amin(T&, U)': a.cc:34:63: warning: no return statement in function returning non-void [-Wreturn-type] 34 | template <class T, class U> amin(T& x, U y) {if (x > y) x = y;} | ^
s988188749
p04049
C++
// /* ID: kfoozmi1 LANG: C++ TASK: */ #include <bits/stdc++.h> using namespace std; #ifdef kfoozminus #define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0) void faltu() { cerr << endl; } template <typename T> void faltu(T a[], int n) { for(int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <typename First, typename ... hello> void faltu(First arg, const hello&... rest) { cerr << arg << ' '; faltu(rest...); } #else #define dbg(args...) #endif #define PB push_back #define F first #define S second #define MP make_pair #define SQR(a) ((a) * (a)) #define vsort(v) sort(v.begin(), v.end()) #define PQ priority_queue #define PI acos(-1) #define EPS 1e-9 #define B1 43 #define B2 43 #define MOD1 1000000007 #define MOD2 1000000009 #define MOD 1000000007 typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //int dx[] = {0, 0, +1, -1}; //int dy[] = {+1, -1, 0, 0}; //int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; //int dy[] = {0, +1, 0, -1, +1, -1, +1, -1}; inline bool checkBit(ll n, int i) { return n & (1LL << i); } inline ll setBit(ll n, int i) { return n | (1LL << i); } inline ll resetBit(ll n, int i) { return n & (~ (1LL << i)); } inline bool EQ(double a, double b) { return fabs(a-b) < EPS; } inline double dist(double ix, double iy, double jx, double jy) { return sqrt(SQR(ix - jx) + SQR(iy - jy)); } #define PMX 1000000 int marked[PMX/64+2]; #define mark(x) marked[x>>6] |= (1<<((x&63)>>1)) #define check(x) (marked[x>>6] & (1<<((x&63)>>1))) bool isPrime(int x) { return (x>1) && ((x==2) || ((x&1) && (!(check(x))))); } void seive(int n) { int i, j; for(i=3; i*i<=n; i+=2) { if(!check(i)) { for(j=i*i; j<=n; j+=i<<1) { mark(j); } } } } ll bigMod(ll a, ll b) { ll r = 1; while(b) { if(b & 1) (r *= a) %= MOD; b >>= 1; (a *= a) %= MOD; } return r; } #define INF 100000000 #define MX 100007 vector<int> edge[MX]; int s; pii n1, n2; vector<int> v[2] (m, 0); pii dfs(int i, int pre) { pii ret = {0, i}; for(int k = 0; k < edge[i].size(); k ++) { if(edge[i][k] == pre) continue; pii p = dfs(edge[i][k], i); if(ret.F < p.F) ret = p; } ret.F ++; return ret; } int m, f; void dfs2(int i, int j, int pre) { v[f][m - j] ++; if(j == m) return ; for(int k = 0; k < edge[i].size(); k ++) { if(edge[i][k] == pre) continue; dfs2(edge[i][k], j + 1, i); } //v[f].PB(edge[i].size() - (i != s)); } int main() { #ifdef kfoozminus //freopen("in", "r", stdin); #endif int n, k, i, sum, ans, u, x; scanf("%d %d", &n, &k); for(i = 1; i < n; i ++) { scanf("%d %d", &u, &x); edge[u].PB(x); edge[x].PB(u); } n1 = dfs(1, -1); n2 = dfs(n1.S, -1); n2.F --; if(n2.F <= k) printf("0\n"); else { k = n2.F - k; dbg(k); m = n2.F; f = 0; s = n1.S; dfs2(n1.S, 0, -1); f = 1; s = n2.S; dfs2(n2.S, 0, -1); for(i = 1; i < v[0].size(); i ++) v[0][i] += v[0][i - 1]; for(i = 1; i < v[1].size(); i ++) v[1][i] += v[1][i - 1]; for(i = 0; i < v[0].size(); i ++) { /*dbg(i, v[0][i]); dbg(i, v[1][i]);*/ } ans = INF; for(i = 0; i <= k; i ++) { sum = 0; if(i) sum += v[0][i - 1]; if(k - i) sum += v[1][(k - i) - 1]; ans = min(sum, ans); } printf("%d\n", ans); } return 0; }
a.cc:108:19: error: 'm' was not declared in this scope 108 | vector<int> v[2] (m, 0); | ^ a.cc:108:23: error: expression list treated as compound expression in initializer [-fpermissive] 108 | vector<int> v[2] (m, 0); | ^
s454964354
p04049
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF INT_MAX/3 #define LINF LLONG_MAX/3 #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(v) (v).begin(),(v).end() #define debug(x) cout<<#x<<":"<<x<<endl #define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N,K; cin >> N >> K; vector<vector<int>> G(N,vector<int>(N)); vector<int> A(N-1),B(N-1); rep(i,N-1){ int a,b;cin>>a>>b; a--; b--; A[i]=a; B[i]=b; G[a].PB(b); G[b].PB(a); } if(K%2==0){ int ans = INF; rep(i,N){ // 点iからの距離を求める queue<int> que; vector<int> d(N,INF); d[i]=0; que.push(i); int tt=0; while(!que.empty()){ tt++; if(tt>4000) assert(false); int q = que.front(); que.pop(); assert(d[q]!|=INF); rep(j,G[q].size()){ int nx = G[q][j]; if(d[nx]!=INF) continue; d[nx] = d[q]+1; que.push(nx); } } int cnt=0; rep(j,N) if(d[j]>K/2) cnt++; //cerr << i << endl; //cerr << d << endl; ans = min(ans,cnt); } cout << ans << endl; }else{ int ans=INF; rep(i,N-1){ int s=A[i],t=B[i]; vector<int> ds(N,INF); queue<int> que; que.push(s); ds[s]=0; int tt=0; while(!que.empty()){ tt++; if(tt>4000) assert(false); int q = que.front(); que.pop(); rep(j,G[q].size()){ int nx = G[q][j]; if(ds[nx]!=INF) continue; ds[nx]=ds[q]+1; que.push(nx); } } vector<int> dt(N,INF); dt[t]=0; que.push(t); tt=0; while(!que.empty()){ tt++; if(tt>4000) assert(false); int q = que.front(); que.pop(); rep(j,G[q].size()){ int nx=G[q][j]; if(dt[nx]!=INF) continue; dt[nx]=dt[q]+1; que.push(nx); } } int cnt=0; rep(j,N){ int d=min(ds[j],dt[j]); if(d>(K-1)/2) cnt++; } ans = min(ans,cnt); } cout << ans << endl; } }
In file included from /usr/include/c++/14/cassert:44, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:106, from a.cc:1: a.cc: In function 'int main()': a.cc:62:28: error: expected ')' before '!' token 62 | assert(d[q]!|=INF); | ^ a.cc:62:28: error: expected ')' before '!' token a.cc:62:17: note: to match this '(' 62 | assert(d[q]!|=INF); | ^~~~~~
s948489429
p04049
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF INT_MAX/3 #define LINF LLONG_MAX/3 #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(v) (v).begin(),(v).end() #define debug(x) cout<<#x<<":"<<x<<endl #define debug2(x,y) cout<<#x<<","<<#y":"<<x<<","<<y<<endl template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N,K; cin >> N >> K; vector<vector<int>> G(N,vector<int>(N)); vector<int> A(N-1),B(N-1); rep(i,N-1){ int a,b;cin>>a>>b; a--; b--; A[i]=a; B[i]=b; G[a].PB(b); G[b].PB(a); } if(K%2==0){ cerr << "case1" << endl; int ans = INF; rep(i,N){ // 点iからの距離を求める queue<int> que; vector<int> d(N,INF); d[i]=0; que.push(i); while(!que.empty()){ int q = que.front(); que.pop(); rep(j,G[q].size()){ int nx = G[q][j]; if(d[nx]!=INF) continue; d[nx] = d[q]+1; que.push(nx); } } int cnt=0; rep(j,N) if(d[j]>K/2) cnt++; //cerr << i << endl; //cerr << d << endl; ans = min(ans,cnt); } cout << ans << endl; }else{ int ans=INF; rep(i,N-1){ int s=A[i],t=B[i]; vector<int> ds(N,INF); queue<int> que; que.push(s); ds[s]=0; int t=0; while(!que.empty()){ t++; if(t>4000) assert(false); int q = que.front(); que.pop(); rep(j,G[q].size()){ int nx = G[q][j]; if(ds[nx]!=INF) continue; ds[nx]=ds[q]+1; que.push(nx); } } vector<int> dt(N,INF); dt[t]=0; que.push(t); t=0; while(!que.empty()){ t++; if(t>4000) assert(false); int q = que.front(); que.pop(); rep(j,G[q].size()){ int nx=G[q][j]; if(dt[nx]!=INF) continue; dt[nx]=dt[q]+1; que.push(nx); } } int cnt=0; rep(j,N){ int d=min(ds[j],dt[j]); if(d>(K-1)/2) cnt++; } ans = min(ans,cnt); } cout << ans << endl; } }
a.cc: In function 'int main()': a.cc:82:17: error: redeclaration of 'int t' 82 | int t=0; | ^ a.cc:77:24: note: 'int t' previously declared here 77 | int s=A[i],t=B[i]; | ^
s736703566
p04049
C++
5555
a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 5555 | ^~~~
s197825051
p04049
C++
//GRL_5A #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <cstdio> using namespace std; #define INF (1<<30) static const int MAX=100000; typedef long long ll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<pint> vpint; #define mp make_pair #define fi first #define se second #define all(v) (v).begin(),(v).end() #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) class Edge{ public: int t,w; Edge(){} Edge(int t,int w): t(t),w(w) {} }; vector<Edge> G[MAX]; int n,d[MAX]; bool vis[MAX]; int cnt; void bfs(int s){ for(int i=0;i<n;i++) d[i]=INF; queue<int> Q; Q.push(s); d[s]=0; int u; while(!Q.empty()){ u=Q.front(); Q.pop(); for(int i=0;i<G[u].size();i++){ Edge e=G[u][i]; if(d[e.t]==INF){ d[e.t]=d[u]+e.w; Q.push(e.t); } } } } int tgt; int tgs; void solve(){ bfs(0); int maxv=0; tgt=0; for(int i=0;i<n;i++){ if(d[i]==INF) continue; if(maxv<d[i]){ maxv=d[i]; tgt=i; } // printf("%d\n", maxv); } bfs(tgt); maxv=0; for(int i=0;i<n;i++){ if(d[i]==INF) continue; maxv=max(maxv,d[i]); if(maxv < d[i]){ maxv = d[i]; tgs = i; } } cout<< "yea" << maxv<<endl; } int main(){ int s,t, k; cin>>n >> k; for(int i=0;i<n-1;i++){ cin>>s>>t; s--; t--; G[s].push_back(Edge(t,1)); G[t].push_back(Edge(s,1)); } int ans = 0; int now = solve(); if(now <= k) printf("%d\n", ans); while(now > k){ int a = G[tgt].size(); int b = G[tgt].size(); if(a <= b){ ans += a; tgt = G[G[tgt][0]].size(); reps(k, 1, a){ tgt = min(G[tgt].size(), G[k].size()); } tgs = G[G[tgs][0]].size(); reps(k, 1, b){ tgs = min(G[tgs].size(), G[k].size()); } } else ans += b; now--; } return 0; }
a.cc: In function 'int main()': a.cc:86:17: error: void value not ignored as it ought to be 86 | int now = solve(); | ~~~~~^~ a.cc:93:12: error: no match for 'operator[]' (operand types are 'std::vector<Edge> [100000]' and '__gnu_cxx::__alloc_traits<std::allocator<Edge>, Edge>::value_type' {aka 'Edge'}) 93 | tgt = G[G[tgt][0]].size(); | ^ a.cc:98:12: error: no match for 'operator[]' (operand types are 'std::vector<Edge> [100000]' and '__gnu_cxx::__alloc_traits<std::allocator<Edge>, Edge>::value_type' {aka 'Edge'}) 98 | tgs = G[G[tgs][0]].size(); | ^
s255794591
p04049
C++
#include <cmath> #include <map> #include<fstream> #include<algorithm> #include <iostream> #include<numeric> #include<utility> #include<functional> #include<stdio.h> #include<assert.h> #include<memory.h> #include<bitset> #include <cassert> #include <stack> #include <ctime> #include <vector> #include <cstdlib> #include <iostream> #include <iomanip> #include <string> #include <ctime> #include <queue> #include <vector> #include <iterator> #include <math.h> #include<cstring> #include <cmath> #include <sstream> #include<cstring> #include<cstdlib> #include <set> #include <cstdio> #include<map> #define all(v) ((v).begin()), ((v).end()) #define sz(v) ((int)((v).size())) #define REP(i, v) for(int i=0;i<sz(v);i++) #define dbg(a) cerr << #a << ": " << (a) << endl #define ll long long #define endl "\n" #define getBit(num,idx) ((num >> idx) & 1) #define setBit(num,idx) num|((1 << idx)) using namespace std; typedef vector<vector<int> > vvi; typedef vector<int> vi; vector<int> leafs; int chCnt[2000+5]; vector<vector<int> > tree(2000+5); int parent[2000+5]; int P[2000+5][50]; int L[2000+5]; bool bad[2000+5]; pair<int,int> bfs(int u) { queue<pair<int,pair<int,int> > > Q; Q.push(make_pair(u,make_pair(0,-1))); int max_distance = 0; int t = u; while(!Q.empty()) { pair<int,pair<int,int> > out = Q.front(); Q.pop(); int idx = out.first; int dis = out.second.first; int p = out.second.second; if(bad[idx]) continue; if(max_distance <= dis){ t = idx; max_distance = dis; } REP(k,tree[idx]) { int next = tree[idx][k]; if(next==p || bad[next])continue; Q.push(make_pair(next,make_pair(dis+1,idx))); } } return make_pair(t,max_distance); } pair<int,pair<int,int> > getDiameter(int idx) { int path = 0; pair<int,int> u = bfs(idx); pair<int,int> v = bfs(u.first); path = max(v.second,path); pair<int,pair<int,int> > PP = make_pair(path,make_pair(u.first,v.first)); return PP; } int solve(int i,int j) { if(j == 0) return parent[i]; if(P[i][j] != -1) return P[i][j]; return P[i][j] = solve(solve(i,j-1),j-1); } int LCA_(int x,int y) { if(L[x] > L[y]) { int tmp = x; x = y; y = tmp; } int log = 25; // fix x to be on the same level as y for(int k = log ; k >= 0 ; k--) { int next = solve(y,k); // <= because we are going upwards if(L[x] <= L[next]) y = next; } // if it was a chain..then it's my ancestor if(x == y) return x; for(int k = log ; k >= 0; k--) { int nextX = solve(x,k); int nextY = solve(y,k); if(nextX != nextY) { // that ancestor that was found is not common x = nextX; y = nextY; } } return parent[x]; } void dfs(int idx,int lvl) { // performs dfs on the tree // store the level, and parent of each node // DFS must be called before any DP function..(obviously). L[idx] = lvl; chCnt[idx] = 0; REP(i,tree[idx]) { int k = tree[idx][i]; if(k == parent[idx]) continue; chCnt[idx]++; parent[k] = idx; dfs(k,lvl + 1); } } inline int dis(int i ,int j) { return L[i] + L[j] - 2 * L[LCA_(i,j)]; } int main() { int N,K; scanf("%d %d",&N,&K); int u,v; for(int i = 0 ; i < N - 1; i++) { scanf("%d %d",&u,&v); --u; --v; tree[u].push_back(v); tree[v].push_back(u); } memset(P,-1,sizeof(P)); parent[n - 1] = n - 1; dfs(n - 1,0); memset(bad,0,sizeof(bad)); int DIA = 0; for(int i = 0 ; i < N ; i++)if(!chCnt[i]) leafs.push_back(i); int removed = 0; while(1) { pair<int,pair<int,int> > PP = getDiameter(n - 1); int firstNode = PP.second.first; int secondNode = PP.second.second; DIA = PP.first; if(DIA <= K) break; int choice = -1; int mini = 1 << 30; REP(k,leafs) { int next = leafs[k]; if(bad[next]) continue; if(dis(next,firstNode) == DIA || dis(next,secondNode) == DIA) { if(parent[next] == (n - 1) || ( chCnt[parent[next]] < mini)) { choice = next; if(parent[next] != 0) mini = chCnt[parent[next]]; else mini = -1; } } } bad[choice] = 1; ++removed; chCnt[parent[choice]]--; if(chCnt[parent[choice]] == 0) { leafs.push_back(parent[choice]); } } printf("%d",removed); }
a.cc: In function 'int main()': a.cc:191:16: error: 'n' was not declared in this scope 191 | parent[n - 1] = n - 1; | ^
s931118063
p04049
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> using Graph = vector<vector<T>>; #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, a) REP(i, 0, a) #define EACH(i, a) for (auto i: a) #define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define HAS(a, x) (a.find(x) != a.end()) #define endl '\n' int N, K; int A[2016], B[2016]; bool used[2016]; vector<int> G[2016]; pair<int, int> solve(int i, int d) { if (d > K) return {0, 0}; // res = self + child num int res = 1; used[i] = true; for (auto j: G[i]) { int mx = 0; if (!used[j]) { auto p = solve(j, d + 1); int n = p.first, r = p.second; if (r == -1 || r + mx > K) { used[i] = false; return {-1, -1}; } mx = max(mx, r); res += n; } } used[i] = false; return {res, mx + 1}; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; rep(i, N - 1) { cin >> A[i] >> B[i]; G[A[i] - 1].push_back(B[i] - 1); G[B[i] - 1].push_back(A[i] - 1); } int ans = N; rep(i, N) { used[i] = true; for (auto j: G[i]) { auto p = solve(j, 1); if (p.second == -1) continue; //if (ans > N - p.first - 1) cout << i << " " << j << endl; ans = min(ans, N - p.first - 1); } used[i] = false; } cout << ans << endl; return 0; }
a.cc: In function 'std::pair<int, int> solve(int, int)': a.cc:38:16: error: 'mx' was not declared in this scope 38 | return {res, mx + 1}; | ^~ a.cc:38:22: error: could not convert '{res, <expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<int, int>' 38 | return {res, mx + 1}; | ^ | | | <brace-enclosed initializer list>
s453307086
p04049
Java
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.StringTokenizer; public class ShortenDiameter { static class P { int front, cost; public P(int f, int c){ front = f; cost = c; } } public static void main(String[] args) { InputReader r = new InputReader(System.in); int n = r.nextInt(); int k = r.nextInt(); ArrayList<Integer> adj[] = new ArrayList[n]; for (int i = 0; i < adj.length; i++) { adj[i] = new ArrayList<Integer>(); } for (int i = 0; i < n - 1; i++) { int from = r.nextInt() - 1; int to = r.nextInt() - 1; adj[from].add(to); adj[to].add(from); } for(int i=0;i<n;i+=10){ Collections.shuffle(adj[i]); } int res = 1 << 28; boolean[] vis = new boolean[n]; for (int i = 0; i < n; i++) { LinkedList<P> q = new LinkedList<P>(); q.add(new P(i,0)); Arrays.fill(vis, false); vis[i] = true; HashSet<Integer> set = new HashSet<Integer>(); int last = -1; while (!q.isEmpty()) { P f = q.removeFirst(); int front = f.front; set.add(front); last = front; int cost = f.cost; if (cost == k) { continue; } for (int x : adj[front]) { if (!vis[x]) { q.add(new P(x, cost+1)); vis[x] = true; } } } Arrays.fill(vis, false); vis[last] = true; q.add(new P(last,0)); int diameter = -1; int reached = 0; HashSet<Integer> set2 = new HashSet<Integer>(); while (!q.isEmpty()) { P f = q.remove(); int front = f.front; int cost = f.cost; reached++; diameter = cost; if (diameter <= k) { last = front; set2.add(front); res = Math.min(res, n - reached); } for (int x : adj[front]) { if (!vis[x] && set.contains(x)) { q.add(new P(x, cost+1)); vis[x] = true; } } } } System.out.println(res); } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public InputReader(FileReader stream) { reader = new BufferedReader(stream); tokenizer = null; } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Main.java:13: error: class ShortenDiameter is public, should be declared in a file named ShortenDiameter.java public class ShortenDiameter { ^ Note: Main.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
s708918595
p04049
C++
#include <bits/stdc++.h> using namespace std; void init_ios() {ios_base::sync_with_stdio(false); cin.tie(nullptr);} int N, K; vector<int> G[2000]; int main() { scanf("%d%d", &N, &K); for (int i = 0, A,B; i < N-1; ++i) { scanf("%d%d", &A, &B); --A, --B; G[A].push_back(B); G[B].push_back(A); } int res = 1<<30; for (int i = 0; i < N; ++i) { vector<int> checked(N, 0); checked[i] = 1; queue<pair<int, int>> q; q.emplace(i, 0); while (q.size()) { auto v = q.top(); q.pop(); checked[v] = 1; if (v.second < K) for (auto& u : G[v.first]) if (!checked[u]) { q.emplace(u, v.second+1); } } int sum = accumulate(checked.begin(), checked.end(), 0); res = min(res, N-sum); } printf("%d\n", res); return 0; }
a.cc: In function 'int main()': a.cc:25:36: error: 'class std::queue<std::pair<int, int> >' has no member named 'top'; did you mean 'pop'? 25 | auto v = q.top(); q.pop(); | ^~~ | pop
s383335047
p04049
C++
#include "inspect.hpp" #include <vector> #include <map> #include <iostream> using namespace std; typedef vector<vector<int>> Graph; void dfs(const Graph &g,vector<int>&v,int cur,int d){ v[cur]=d; for(auto &e:g[cur])if(!v[e])dfs(g,v,e,d+1); } typedef pair<int, int> Result; Result visit(int p, int v, const Graph &g) { Result r(0, v); for(auto &e:g[v]) if (e != p) { Result t = visit(v, e, g); t.first += 1; if (r.first < t.first) r = t; } return r; } int diameter(const Graph &g) { Result r = visit(-1, 0, g); Result t = visit(-1, r.second, g); return t.first; // (r.second, t.second) is farthest pair } int main(){ const int INF=1<<29; int n,k,R=INF; scanf("%d%d",&n,&k); vector<int>deg(n); Graph g(n); for(int i=0;i<n-1;i++){ int a,b; scanf("%d%d",&a,&b); a--;b--; deg[a]++;deg[b]++; g[a].push_back(b); g[b].push_back(a); } for(int i=0;i<n;i++){ if(deg[i]==0)return 1; if(deg[i]==1){ //点iは最遠点の1つ vector<int>v(n); dfs(g,v,i,1); int r=0,mi=0; for(int j=0;j<n;j++){ if(v[j]-1>k)r++; mi=max(mi,v[j]-1); } if(mi==diameter(g))R=min(R,r); } } if(R==INF)return 1; printf("%d\n",R); }
a.cc:1:10: fatal error: inspect.hpp: No such file or directory 1 | #include "inspect.hpp" | ^~~~~~~~~~~~~ compilation terminated.
s694540399
p04049
C++
#include <iomanip> #include <utility> #include <algorithm> #include <type_traits> #include <set> #include <string> #include <iostream> #include <fstream> #include <cassert> #include <memory> #include <unordered_set> #include <unordered_map> #include <set> #include <queue> #include <vector> #include <array> #include <chrono> #include <random> #include <forward_list> #include <iomanip> #include <functional> using namespace std; #define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i) #if 0 int main() { std::ofstream out("out.txt"); out << 2000 << ' ' << 9; for (size_t i = 1; i < 2000; ++i) { out << i << ' ' << i+1 << '\n'; } } #else typedef int Weight; struct Edge { int dst; Edge(int dst) : dst(dst){ } }; typedef vector<Edge> Edges;//辺の集合 //typedef vector<Edges> Graph;//[頂点] typedef std::array<Edges, 3000> Graph;//[頂点] std::array<bool, 3000> unenabled; typedef std::pair<Weight, std::vector<int>> Result;//距離、頂点 Result visit(int p, int v, const Graph &g) { Result r; r.first = 0; r.second.push_back(v); for(auto& e : g[v]) { if (e.dst != p) { Result t = visit(v, e.dst, g); t.first += 1; if (r.first <= t.first) { if (r.first < t.first) { r = t; } else { //r.first == t.first r.second.insert(r.second.end(), t.second.begin(), t.second.end()); } } } } std::sort(r.second.begin(), r.second.end()); r.second.erase(std::unique(r.second.begin(), r.second.end()), r.second.end()); return r; } int main() { Graph g; int N; int K; cin >> N >> K; MFOR(i, N-1) { int a, b; cin >> a >> b; g[a].emplace_back(b); g[b].emplace_back(a); } Result r = visit(-1, 1, g); Result t = visit(-1, r.second.front(), g); //t.firstは最大距離 // (r.second, t.second) is farthest pair int result = 0; while (t.first > K) { --t.first; if (r.second.size() <= t.second.size()) { //r側のが頂点が少ない result += r.second.size(); std::vector<int> temp; for (auto& i : r.second) { unenabled[i] = true; for (auto& j : g[i]) { if (unenabled[j.dst] == false) { temp.push_back(j.dst); } } } std::sort(temp.begin(), temp.end()); temp.erase(std::unique(temp.begin(), temp.end()), temp.end()); r.second = std::move(temp); } else { //t側のが頂点が少ない result += t.second.size(); std::vector<int> temp; for (auto& i : t.second) { unenabled[i] = true; for (auto& j : g[i]) { if (unenabled[j.dst] == false) { temp.push_back(j.dst); } } } std::sort(temp.begin(), temp.end()); temp.erase(std::unique(temp.begin(), temp.end()), temp.end()); t.second = std::move(temp); } } cout << result; }
a.cc:27: error: unterminated #else 27 | #if 0
s192780961
p04049
C++
#include "inspect.hpp" #include <vector> #include <map> #include <iostream> using namespace std; typedef vector<vector<int>> Graph; void dfs(const Graph &g,vector<int>&v,int cur,int d){ v[cur]=d; for(auto &e:g[cur])if(!v[e])dfs(g,v,e,d+1); } typedef pair<int, int> Result; Result visit(int p, int v, const Graph &g) { Result r(0, v); for(auto &e:g[v]) if (e != p) { Result t = visit(v, e, g); t.first += 1; if (r.first < t.first) r = t; } return r; } int diameter(const Graph &g,int t) { Result x = visit(-1, t, g); return x.first; } int main(){ const int INF=1<<29; int n,k,R=INF; scanf("%d%d",&n,&k); vector<int>deg(n); Graph g(n); for(int i=0;i<n-1;i++){ int a,b; scanf("%d%d",&a,&b); a--;b--; deg[a]++;deg[b]++; g[a].push_back(b); g[b].push_back(a); } for(int i=0;i<n;i++){ if(deg[i]==0)return 1; if(deg[i]==1){ //点iは最遠点の1つ vector<int>v(n); dfs(g,v,i,1); int r=0,mi=0; for(int j=0;j<n;j++){ if(v[j]-1>k)r++; mi=max(mi,v[j]-1); } if(mi==diameter(g,i))R=min(R,r); } } if(R==INF)return 1; printf("%d\n",R); }
a.cc:1:10: fatal error: inspect.hpp: No such file or directory 1 | #include "inspect.hpp" | ^~~~~~~~~~~~~ compilation terminated.
s764292203
p04049
C++
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <vector> #include <string> #include <queue> #include <deque> #include <list> #include <stack> #include <set> #include <map> #include <algorithm> #define int long long using namespace std; int N, K; vector<int> next[2000]; int dfs(int now, int prev, int left) { if (left == 0) return 1; int ret = 0; for (int i = 0; i < next[now].size(); i++) { if (prev == next[now][i]) continue; ret += dfs(next[now][i], now, left - 1); } return ret + 1; } int count(int num) { return dfs(num, -1, K); } signed main() { cin >> N >> K; for (int i = 0; i < N-1; i++) { int A, B; cin >> A >> B; A--; B--; next[A].push_back(B); next[B].push_back(A); } int ret = 0; for (int i = 0; i < N; i++) { if (next[i].size() >= 2) continue; ret = max(count(i), ret); } cout << (N - ret) << endl; return 0; }
a.cc: In function 'long long int dfs(long long int, long long int, long long int)': a.cc:29:25: error: reference to 'next' is ambiguous 29 | for (int i = 0; i < next[now].size(); i++) { | ^~~~ In file included from /usr/include/c++/14/string:47, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:23:13: note: 'std::vector<long long int> next [2000]' 23 | vector<int> next[2000]; | ^~~~ a.cc:30:21: error: reference to 'next' is ambiguous 30 | if (prev == next[now][i]) continue; | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:23:13: note: 'std::vector<long long int> next [2000]' 23 | vector<int> next[2000]; | ^~~~ a.cc:31:20: error: reference to 'next' is ambiguous 31 | ret += dfs(next[now][i], now, left - 1); | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:23:13: note: 'std::vector<long long int> next [2000]' 23 | vector<int> next[2000]; | ^~~~ a.cc: In function 'int main()': a.cc:48:9: error: reference to 'next' is ambiguous 48 | next[A].push_back(B); | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:23:13: note: 'std::vector<long long int> next [2000]' 23 | vector<int> next[2000]; | ^~~~ a.cc:49:9: error: reference to 'next' is ambiguous 49 | next[B].push_back(A); | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:23:13: note: 'std::vector<long long int> next [2000]' 23 | vector<int> next[2000]; | ^~~~ a.cc:54:13: error: reference to 'next' is ambiguous 54 | if (next[i].size() >= 2) continue; | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:23:13: note: 'std::vector<long long int> next [2000]' 23 | vector<int> next[2000]; | ^~~~
s087010688
p04049
C++
#include<stdio.h> #include<algorithm> #include<vector> using namespace std; int n,k; vector<int> e[2222]; int dp[2222][2222]; int tmp[2222]; void upd(int&x,int y){ if(x==-1 || x>y)x=y; } void dfs(int x,int f){ dp[x][0] = 1; for(int i=1; i<=k; i++) dp[x][i] = 0; for(vector<int>::iterator it = e[x].begin(); it!=e[x].end(); it++){ int y=*it; if(y == f)continue; dfs(y,x); memset(tmp,-1,sizeof(tmp)); for(int j=0; j<=k; j++){ if(j<k)upd(tmp[max(j+1,k-j)],dp[y][j]+dp[x][k-j]); if(j)upd(tmp[max(j,k-j+1)],dp[y][k-j]+dp[x][j]); if(j==0)upd(tmp[j], dp[x][0] + dp[y][0]);else if(j*2-1<=k) upd(tmp[j], dp[x][j] + dp[y][j-1]); } for(int j=0; j<=k; j++){ dp[x][j] = tmp[j]; if(j)dp[x][j] = min(dp[x][j],dp[x][j-1]); } } // for(int j=0; j<=k; j++) // printf("%d %d: %d\n", x, j, dp[x][j]); } int main(){ scanf("%d%d",&n,&k); ++k; for(int i=1; i<n; i++){ int x,y; scanf("%d%d",&x,&y); e[x].push_back(y); e[y].push_back(x); } dfs(1,1); printf("%d\n",dp[1][k]); return 0; }
a.cc: In function 'void dfs(int, int)': a.cc:21:17: error: 'memset' was not declared in this scope 21 | memset(tmp,-1,sizeof(tmp)); | ^~~~~~ a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 3 | #include<vector> +++ |+#include <cstring> 4 | using namespace std;
s121730252
p04049
C++
#include <bits/stdc++.h> #define REP(i, a, b) for (int i = a; i <= b; ++i) #define RVC(i, S) for (int i = 0; i < S.size(); ++i) using namespace std; set<int>::iterator it; int n, k, dep[2005], sz[2005]; set<int> Tree[2005]; void dfs(int x, int fa){ dep[x] = dep[fa] + 1; for (it = Tree[x].begin(); it != Tree[x].end(); ++it) if (*it != fa) dfs(*it, x); } int diam(int x, int &l, int &r){ dep[0] = -1; dfs(x, 0); l = x; REP(i, 1, n) if (sz[i] && dep[i] > dep[l]) l = i; dfs(l, 0); r = x; REP(i, 1, n) if (sz[i] && dep[i] > dep[r]) r = i; return dep[r]; } int main(){ scanf("%d%d", &n, &k); REP(i, 1, n - 1){ int u, v; scanf("%d%d", &u, &v); Tree[u].insert(v); Tree[v].insert(u); ++sz[u]; ++sz[v]; } //printf("initial diameter = %d\n", diam(l, l, r)); while (diam(r, l, r) > k){ ++ans; if (sz[*Tree[l].begin()] > sz[*Tree[r].begin()]) swap(l, r); int fa = *Tree[l].begin(); --sz[l]; --sz[fa]; Tree[l].erase(fa); Tree[fa].erase(l); } printf("%d\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:37:21: error: 'r' was not declared in this scope 37 | while (diam(r, l, r) > k){ | ^ a.cc:37:24: error: 'l' was not declared in this scope 37 | while (diam(r, l, r) > k){ | ^ a.cc:38:19: error: 'ans' was not declared in this scope; did you mean 'abs'? 38 | ++ans; | ^~~ | abs a.cc:46:24: error: 'ans' was not declared in this scope; did you mean 'abs'? 46 | printf("%d\n", ans); | ^~~ | abs
s314440566
p04049
C++
#include <bits/stdc++.h> using namespace std; #define dbgs(x) cerr << (#x) << " --> " << (x) << ' ' #define dbg(x) cerr << (#x) << " --> " << (x) << endl #define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++) #define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++) #define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--) #define type(x) __typeof(x.begin()) #define orta (bas + son >> 1) #define sag (k + k + 1) #define sol (k + k) #define pb push_back #define mp make_pair #define nd second #define st first #define endl '\n' typedef pair < int ,int > pii; typedef long long ll; const long long linf = 1e18+5; int mod = (int) 1e9 + 7; const int logN = 17; const int inf = 1e9 + 9; const int N = 2e5 + 5; int n, m, x, y, z, t, k, q, dp[N], a[N]; vector< int > v[N]; int ans; int solve(int node, int root) { int mx1 = 0, mx2 = 0; foreach(it, v[node]) if(*it != root) { int t = solve(*it, node) + 1; if(t >= mx1) { mx2 = mx1; mx1 = t; } else if(mx2 < t) mx2 = t; } if(mx1 + mx2 > k) { ans++; return -1; } return mx1; } int main() { scanf("%d %d", &n, &k); FOR(i, 2, n) { scanf("%d %d", &x, &y); v[x].pb(y); v[y].pb(x); } ll a = inf; FOR(i, 1, n) { ans = 0; solve(i, 0); a = min(a, ans); } cout << a << endl; }
a.cc: In function 'int main()': a.cc:69:16: error: no matching function for call to 'min(ll&, int&)' 69 | a = min(a, ans); | ~~~^~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:69:16: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 69 | a = min(a, ans); | ~~~^~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:69:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 69 | a = min(a, ans); | ~~~^~~~~~~~
s245344118
p04050
C++
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); } void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); } string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; } // ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- // void solve(){ int n = scan!int; int m = scan!int; int[] as = scan!int(m); int[] odds, evens; foreach(a; as) if(a % 2) odds ~= a; else evens ~= a; if(odds.length > 2){ "Impossible".writeln; return; } int[] ans, bns; if(odds.length == 0){ ans = evens; foreach(a; evens) bns ~= a; bns[0] -= 1; bns ~= 1; } else if(odds.length == 1){ ans = odds ~ evens; foreach(a; evens) bns ~= a; if(bns.length) bns[0] += odds[0] - 1; else if(odds[0] > 1) bns ~= odds[0] - 1; else{ "Impossible".writeln; return; } bns ~= 1; } else if(odds.length == 2){ ans = [odds[0]] ~ evens ~ odds[1]; foreach(a; evens) bns ~= a; if(bns.length) bns[0] += odds[0] - 1; else if(odds[0] > 1) bns ~= odds[0] - 1; bns ~= odds[1] + 1; } print(ans.unsplit); print(bns.length); print(bns.unsplit); }
a.cc:1:1: error: 'import' does not name a type 1 | import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container; | ^~~~~~ a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:2:1: error: 'import' does not name a type 2 | import std.math, std.random, std.bigint, std.datetime, std.format; | ^~~~~~ a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:3:6: error: variable or field 'main' declared void 3 | void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; | ^~~~ a.cc:3:11: error: 'string' was not declared in this scope 3 | void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; | ^~~~~~ a.cc:3:18: error: expected primary-expression before ']' token 3 | void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; | ^ a.cc:4:6: error: variable or field 'log' declared void 4 | void log(A ...)(lazy A a){ if(DEBUG) print(a); } | ^~~ a.cc:4:10: error: 'A' was not declared in this scope 4 | void log(A ...)(lazy A a){ if(DEBUG) print(a); } | ^ a.cc: In function 'void print()': a.cc:5:15: error: 'writeln' was not declared in this scope 5 | void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } | ^~~~~~~ a.cc: At global scope: a.cc:5:35: error: variable or field 'print' declared void 5 | void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } | ^~~~~ a.cc:5:41: error: 'T' was not declared in this scope 5 | void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } | ^ a.cc:5:69: error: variable or field 'print' declared void 5 | void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } | ^~~~~ a.cc:5:75: error: 'T' was not declared in this scope 5 | void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } | ^ a.cc:5:78: error: 'A' was not declared in this scope 5 | void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); } | ^ a.cc:6:1: error: 'string' does not name a type 6 | string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); } | ^~~~~~ a.cc:7:1: error: 'string' does not name a type 7 | string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } | ^~~~~~ a.cc:8:1: error: 'T' does not name a type 8 | T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } | ^ a.cc:8:34: error: 'T' does not name a type 8 | T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; } | ^ a.cc:9:1: error: 'T' does not name a type 9 | T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; } | ^ a.cc:9:58: error: 'T' does not name a type 9 | T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; } | ^ a.cc: In function 'void solve()': a.cc:14:11: error: 'scan' was not declared in this scope 14 | int n = scan!int; | ^~~~ a.cc:16:6: error: structured binding declaration cannot have type 'int' 16 | int[] as = scan!int(m); | ^~ a.cc:16:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto' a.cc:16:6: error: empty structured binding declaration a.cc:16:9: error: expected initializer before 'as' 16 | int[] as = scan!int(m); | ^~ a.cc:18:6: error: structured binding declaration cannot have type 'int' 18 | int[] odds, evens; | ^~ a.cc:18:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto' a.cc:18:6: error: empty structured binding declaration a.cc:18:9: error: expected initializer before 'odds' 18 | int[] odds, evens; | ^~~~ a.cc:19:11: error: 'a' was not declared in this scope 19 | foreach(a; as) if(a % 2) odds ~= a; else evens ~= a; | ^ a.cc:19:14: error: 'as' was not declared in this scope 19 | foreach(a; as) if(a % 2) odds ~= a; else evens ~= a; | ^~ a.cc:19:39: error: 'else' without a previous 'if' 19 | foreach(a; as) if(a % 2) odds ~= a; else evens ~= a; | ^~~~ a.cc:19:44: error: 'evens' was not declared in this scope 19 | foreach(a; as) if(a % 2) odds ~= a; else evens ~= a; | ^~~~~ a.cc:21:6: error: 'odds' was not declared in this scope 21 | if(odds.length > 2){ | ^~~~ a.cc:22:18: error: request for member 'writeln' in '"Impossible"', which is of non-class type 'const char [11]' 22 | "Impossible".writeln; | ^~~~~~~ a.cc:26:6: error: structured binding declaration cannot have type 'int' 26 | int[] ans, bns; | ^~ a.cc:26:6: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto' a.cc:26:6: error: empty structured binding declaration a.cc:26:9: error: expected initializer before 'ans' 26 | int[] ans, bns; | ^~~ a.cc:27:6: error: 'odds' was not declared in this scope 27 | if(odds.length == 0){ | ^~~~ a.cc:28:5: error: 'ans' was not declared in this scope 28 | ans = evens; | ^~~ a.cc:29:14: error: expected ')' before ';' token 29 | foreach(a; evens) bns ~= a; | ~ ^ | ) a.cc:29:21: error: expected ';' before ')' token 29 | foreach(a; evens) bns ~= a; | ^ | ; a.cc:30:5: error: 'bns' was not declared in this scope 30 | bns[0] -= 1; | ^~~ a.cc:31:8: error: expected ';' before '~' token 31 | bns ~= 1; | ^~ | ; a.cc:34:5: error: 'ans' was not declared in this scope 34 | ans = odds ~ evens; | ^~~ a.cc:35:14: error: expected ')' before ';' token 35 | foreach(a; evens) bns ~= a; | ~ ^ | ) a.cc:35:21: error: expected ';' before ')' token 35 | foreach(a; evens) bns ~= a; | ^ | ; a.cc:36:8: error: 'bns' was not declared in this scope 36 | if(bns.length) bns[0] += odds[0] - 1; | ^~~ a.cc:37:29: error: expected ';' before '~' token 37 | else if(odds[0] > 1) bns ~= odds[0] - 1; | ^~ | ; a.cc:38:24: error: request for member 'writeln' in '"Impossible"', which is of non-class type 'const char [11]' 38 | else{ "Impossible".writeln; return; } | ^~~~~~~ a.cc:39:5: error: 'bns' was not declared in this scope 39 | bns ~= 1; | ^~~ a.cc:42:5: error: 'ans' was not declared in this scope 42 | ans = [odds[0]] ~ evens ~ odds[1]; | ^~~ a.cc:42:16: error: expected ',' before '[' token 42 | ans = [odds[0]] ~ evens ~ odds[1]; | ^ | , a.cc:42:16: error: expected identifier before '[' token a.cc: In lambda function: a.cc:42:21: error: expected '{' before '~' token 42 | ans = [odds[0]] ~ evens ~ odds[1]; | ^ a.cc: In function 'void solve()': a.cc:43:14: error: expected ')' before ';' token 43 | foreach(a; evens) bns ~= a; | ~ ^ | ) a.cc:43:21: error: expected ';' before ')' token 43 | foreach(a; evens) bns ~= a; | ^ | ; a.cc:44:8: error: 'bns' was not declared in this scope 44 | if(bns.length) bns[0] += odds[0] - 1; | ^~~ a.cc:45:29: error: expected ';' before '~' token 45 | else if(odds[0] > 1) bns ~= odds[0] - 1; | ^~ | ; a.cc:46:5: error: 'bns' was not declared in this scope 46 | bns ~= odds[1] + 1; | ^~~ a.cc:49:9: error: 'ans' was not declared in this scope 49 | print(ans.unsplit); | ^~~ a.cc:50:9: error: 'bns' was not declared in this scope 50 | print(bns.length); | ^~~
s840622564
p04050
C++
netman TLE #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ld EPS = 1e-11; const ld PI = acos(-1.0); const int INF = (int)1e9 + 5; const ll LINF = (ll)1e18 + 5; template<class T> ll abs(const T & x) { return x < 0 ? -x : x; } template<class T> ll round(const T & x) { return x < 0 ? x - 0.5 : x + 0.5; } template<class T> bool chmin(T & x, const T & y) { if (y < x) { x = y; return true; } return false; } template<class T> bool chmax(T & x, const T & y) { if (x < y) { x = y; return true; } return false; } #define all(a) (a).begin(), (a).end() const int N = 100100; int n; int p[N], sz[N], tp[N], tsz[N]; int cnt, tcnt; void init() { for (int i = 1; i <= n; i++) { p[i] = i; sz[i] = 1; } cnt = n; } int get(int x) { if (x == p[x]) return x; return p[x] = get(p[x]); } bool unite(int x, int y) { x = get(x); y = get(y); if (x == y) return false; if (sz[x] > sz[y]) swap(x, y); sz[y] += sz[x]; p[x] = y; cnt--; return true; } vector<int> generate() { int cnt = rand() % min(n, 1000) + 1; static vector<int> res; res.resize(cnt); static vector<int> perm(n); for (int i = 0; i < n; i++) { perm[i] = i + 1; } random_shuffle(all(perm)); sort(perm.begin(), perm.begin() + cnt); int l = 0; perm[cnt - 1] = n; for (int i = 0; i < cnt; i++) { res[i] = perm[i] - l; l = perm[i]; } return res; } void check(const vector<int> & a, vector<int> & b) { static int iterNum = 0; memcpy(p, tp, sizeof(p[0]) * (n + 1)); memcpy(sz, tsz, sizeof(sz[0]) * (n + 1)); cnt = tcnt; int st = 1; for (int & x : b) { int l = st; int r = l + x - 1; while (l < r) { unite(l, r); l++; r--; } st += x; } if (cnt == 1) { for (const int & x : a) { printf("%d ", x); } puts(""); printf("%d\n", (int)b.size()); for (int & x : b) { printf("%d ", x); } puts(""); exit(0); } } void iteration(const vector<int> & a) { static int iterNum = 0; memcpy(p, tp, sizeof(p[0]) * (n + 1)); memcpy(sz, tsz, sizeof(sz[0]) * (n + 1)); cnt = tcnt; vector<int> b = generate(); int st = 1; for (int & x : b) { int l = st; int r = l + x - 1; while (l < r) { unite(l, r); l++; r--; } st += x; } if (cnt == 1) { for (const int & x : a) { printf("%d ", x); } puts(""); printf("%d\n", (int)b.size()); for (int & x : b) { printf("%d ", x); } puts(""); exit(0); } } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #else #endif int m; cin >> n >> m; vector<int> a(m); for (int & x : a) { cin >> x; } for (int outerIter = 0; outerIter < 10; outerIter++) { random_shuffle(all(a)); int st = 1; init(); for (int & x : a) { int l = st; int r = l + x - 1; while (l < r) { unite(l, r); l++; r--; } st += x; } memcpy(tp, p, sizeof(p[0]) * (n + 1)); memcpy(tsz, sz, sizeof(sz[0]) * (n + 1)); tcnt = cnt; int iter = (int)1e7 / n / 15; while (iter--) { iteration(a); } } for (int z = 0; z < 20; z++) { vector<int> b; int s = n; while (s) { if (s == 3) { b.push_back(s); s = 0; } else { int r = (rand() % 2 == 0 ? 2 : 3); b.push_back(r); s -= r; } } check(a, b); } puts("Impossible"); }
a.cc:1:1: error: 'netman' does not name a type 1 | netman | ^~~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:62, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:5: /usr/include/c++/14/ext/type_traits.h:164:35: error: 'constexpr const bool __gnu_cxx::__is_null_pointer' redeclared as different kind of entity 164 | __is_null_pointer(std::nullptr_t) | ^ /usr/include/c++/14/ext/type_traits.h:159:5: note: previous declaration 'template<class _Type> constexpr bool __gnu_cxx::__is_null_pointer(_Type)' 159 | __is_null_pointer(_Type) | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/ext/type_traits.h:164:26: error: 'nullptr_t' is not a member of 'std'; did you mean 'nullptr_t'? 164 | __is_null_pointer(std::nullptr_t) | ^~~~~~~~~ In file included from /usr/include/c++/14/cstddef:50, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:41: /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:443:29: note: 'nullptr_t' declared here 443 | typedef decltype(nullptr) nullptr_t; | ^~~~~~~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, from /usr/include/c++/14/bits/stl_algobase.h:64: /usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std'; did you mean 'nullptr_t'? 666 | struct is_null_pointer<std::nullptr_t> | ^~~~~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:443:29: note: 'nullptr_t' declared here 443 | typedef decltype(nullptr) nullptr_t; | ^~~~~~~~~ /usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid 666 | struct is_null_pointer<std::nullptr_t> | ^ /usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid 670 | struct is_null_pointer<const std::nullptr_t> | ^ /usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid 674 | struct is_null_pointer<volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid 678 | struct is_null_pointer<const volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^ /usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1438 | : public integral_constant<std::size_t, 0> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid 1438 | : public integral_constant<std::size_t, 0> { }; | ^ /usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared 1440 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope 1441 | struct rank<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid 1441 | struct rank<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:2086:26: error: 'std::size_t' has not been declared 2086 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2087:30: error: '_Size' was not declared in this scope 2087 | struct remove_extent<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2087:36: error: template argument 1 is invalid 2087 | struct remove_extent<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2099:26: error: 'std::size_t' has not been declared 2099 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2100:35: error: '_Size' was not declared in this scope 2100 | struct remove_all_extents<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2100:41: error: template argument 1 is invalid 2100 | struct remove_all_extents<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2171:12: error: 'std::size_t' has not been declared 2171 | template<std::size_t _Len> | ^~~ /usr/include/c++/14/type_traits:2176:30: error: '_Len' was not declared in this scope 2176 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2194:12: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2194:30: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2195:55: error: '_Len' was not declared in this scope 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^~~~ /usr/include/c++/14/type_traits:2195:59: error: template argument 1 is invalid 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^ /usr/include/c++/14/type_traits:2202:30: error: '_Len' was not declared in this scope 2202 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2203:44: error: '_Align' was not declared in this scope 2203 | struct __attribute__((__aligned__((_Align)))) { } __align; | ^~~~~~ In file included from /usr/include/c++/14/bits/stl_tempbuf.h:59, from /usr/include/c++/14/bits/stl_algo.h:69, from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function 131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~~~ /usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive] 132 | __attribute__((__externally_visible__)); | ^ /usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function 133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~~~ /usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:134:41: error: attributes after parenthesized initializer ignored [-fpermissive] 134 | __attribute__((__externally_visible__)); | ^ /us
s244183752
p04050
C++
#include <algorithm> #include <iostream> #include <cstring> #include <vector> using namespace std; const int MAX_N = 1e5 + 5; int n, m; int Arr[MAX_N]; int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> Arr[i]; assert(n % 2); if (n % 2) { int num = 0; for (int i = 0; i < n; i++) num += (Arr[i] & 1); cout << "Impossible\n"; return 0; } return 0; }
a.cc: In function 'int main()': a.cc:17:9: error: 'assert' was not declared in this scope 17 | assert(n % 2); | ^~~~~~ a.cc:5:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>' 4 | #include <vector> +++ |+#include <cassert> 5 | using namespace std;
s300935899
p04050
C++
#include <algorithm> #include <iostream> #include <cstirng> #include <vector> using namespace std; const int MAX_N = 1e5 + 5; int n, m; int Arr[MAX_N]; int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> Arr[i]; assert(n % 2); if (n % 2) { int num = 0; for (int i = 0; i < n; i++) num += (Arr[i] & 1); cout << "Impossible\n"; return 0; } return 0; }
a.cc:3:10: fatal error: cstirng: No such file or directory 3 | #include <cstirng> | ^~~~~~~~~ compilation terminated.
s145150281
p04050
C++
#include <iostream> #include <sstream> #include <vector> #define MAX_N 100000 #define MAX_M 100 using namespace std; int N, M; int A[MAX_N]; vector<int> solve() { vector<int> B; vector<int> O; // 奇数のインデックス for ( int i = 0; i < M; i++ ) if ( A[i] % 2 ) O.push_back( i ); switch ( O.size() ) { case 2: swap( A[O[1]], A[M - 1] ); case 1: swap( A[O[0]], A[0] ); break; case 0: break; default: return B; } if ( A[0] > 1 ) B.push_back( A[0] - 1 ); switch ( M ) { case 1: B.push_back( 1 ); break; default: for ( int i = 1; i < M - 1; i++ ) B.push_back( A[i] ); B.push_back( A[M - 1] + 1 ); } return B; } int main( int argc, char **argv ) { cin >> N >> M; for ( int i = 0; i < M; i++ ) cin >> A[i]; auto B = solve(); if ( B.size() == 0 ) cout << "Impossible" << endl; else { copy( A, A + M, ostream_iterator<int>( cout, " " ) ); cout << endl; cout << B.size() << endl; copy( B.begin(), B.end(), ostream_iterator<int>( cout, " " ) ); cout << endl; } return 0; }
a.cc: In function 'int main(int, char**)': a.cc:60:25: error: 'ostream_iterator' was not declared in this scope 60 | copy( A, A + M, ostream_iterator<int>( cout, " " ) ); | ^~~~~~~~~~~~~~~~ a.cc:4:1: note: 'std::ostream_iterator' is defined in header '<iterator>'; this is probably fixable by adding '#include <iterator>' 3 | #include <vector> +++ |+#include <iterator> 4 | a.cc:60:42: error: expected primary-expression before 'int' 60 | copy( A, A + M, ostream_iterator<int>( cout, " " ) ); | ^~~ a.cc:65:52: error: expected primary-expression before 'int' 65 | copy( B.begin(), B.end(), ostream_iterator<int>( cout, " " ) ); | ^~~
s078788968
p04050
C++
#include <iostream> #include <vector> #define MAX_N 100000 #define MAX_M 100 using namespace std; int N, M; int A[MAX_N]; vector<int> solve() { vector<int> B; vector<int> O; // 奇数のインデックス for ( int i = 0; i < M; i++ ) if ( A[i] % 2 ) O.push_back( i ); switch ( O.size() ) { case 2: swap( A[O[1]], A[M - 1] ); case 1: swap( A[O[0]], A[0] ); break; case 0: break; default: return B; } if ( A[0] > 1 ) B.push_back( A[0] - 1 ); switch ( M ) { case 1: B.push_back( 1 ); break; default: for ( int i = 1; i < M - 1; i++ ) B.push_back( A[i] ); B.push_back( A[M - 1] + 1 ); } return B; } int main( int argc, char **argv ) { cin >> N >> M; for ( int i = 0; i < M; i++ ) cin >> A[i]; auto B = solve(); if ( B.size() == 0 ) cout << "Impossible" << endl; else { copy( A, A + M, ostream_iterator<int>( cout, " " ) ); cout << endl; cout << B.size() << endl; copy( B.begin(), B.end(), ostream_iterator<int>( cout, " " ) ); cout << endl; } return 0; }
a.cc: In function 'int main(int, char**)': a.cc:59:25: error: 'ostream_iterator' was not declared in this scope 59 | copy( A, A + M, ostream_iterator<int>( cout, " " ) ); | ^~~~~~~~~~~~~~~~ a.cc:3:1: note: 'std::ostream_iterator' is defined in header '<iterator>'; this is probably fixable by adding '#include <iterator>' 2 | #include <vector> +++ |+#include <iterator> 3 | a.cc:59:42: error: expected primary-expression before 'int' 59 | copy( A, A + M, ostream_iterator<int>( cout, " " ) ); | ^~~ a.cc:64:52: error: expected primary-expression before 'int' 64 | copy( B.begin(), B.end(), ostream_iterator<int>( cout, " " ) ); | ^~~