submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s670532139
p04008
C++
to be implemented
a.cc:1:1: error: 'to' does not name a type; did you mean 'auto'? 1 | to be implemented | ^~ | auto
s257675824
p04008
C++
#include <iostream> #include <cassert> #include <climits> #include <bitset> #include <stack> #include <queue> #include <iomanip> #include <limits> #include <string> #include <cmath> #include <set> #include <map> #include <math.h> #include <algorithm> #include <vector> #include <string.h> #include <tuple> using namespace std; typedef long long ll; typedef pair<ll,ll> P; long long int INF = 1e18; long long int mod = 1000000007; double Pi = 3.1415926535897932384626; vector<ll> G[500005]; vector<P> tree[500010]; priority_queue <ll> pql; priority_queue <P> pqp; //big priority queue priority_queue <ll,vector<ll>,greater<ll> > pqls; priority_queue <P,vector<P>,greater<P> > pqps; //small priority queue //top pop int dx[8]={1,0,-1,0,1,1,-1,-1}; int dy[8]={0,1,0,-1,1,-1,-1,1}; char dir[] = "RULD"; //↓,→,↑,← #define p(x) cout<<x<<endl; #define el cout<<endl; #define pe(x) cout<<x<<" "; #define ps(x) cout<<fixed<<setprecision(25)<<x<<endl; #define pu(x) cout<<x; #define re(i,n) for(i=0;i<n;i++); #define pb push_back #define lb lower_bound #define ub upper_bound #define deba(x) cout<< #x << " = " << x <<endl ll rui(ll number1,ll number2){ if(number2 == 0){ return 1; }else{ ll number3 = rui(number1,number2 / 2); number3 *= number3; number3 %= mod; if(number2%2==1){ number3 *= number1; number3 %= mod; } return number3; } } ll gcd(ll number1,ll number2){ if(number1 > number2){ swap(number1 , number2); } if(number1 == 0 || number1 == number2){ return number2; }else{ return gcd(number2 % number1 , number1); } } ll i,j,k,ii,jj,n,m,a,b,c,d,e,g,h,w,num,sum,ans; ll x[500005],y[500005],z[500005]; ll l[500005],r[500005]; ll dp[100005][105]; char s[500005],t[500005]; ll dfs(ll v,ll p,ll cost){ ll ans1 = 0,ans2 = 0; if(cost <= 1000 && dp[v][cost] != -1){ return dp[v][cost]; } if(cost > k){ ans2 = 1; for(int i=0;i<G[v].size();i++){ if(G[v][i] == p)continue; ans2 += dfs(G[v][i],v,2); } // pe(v);pe("cost > k");p(ans2); dp[v][cost] = ans2; return ans2; }else{ for(int i=0;i<G[v].size();i++){ if(G[v][i] == p)continue; ans1 += dfs(G[v][i],v,cost + 1); } if(ans1 == 0 || cost <= 1){ // pe(v);pe("ans1 == 0 || cost <= 1")p(ans1); dp[v][cost] = ans1; return ans1; }else{ ans2 = 1; for(int i=0;i<G[v].size();i++){ if(G[v][i] == p)continue; ans2 += dfs(G[v][i],v,2); } // pe(v);pe("min(ans1,ans2)");p(min(ans1,ans2)); dp[v][cost] = min(ans1,ans2); return min(ans1,ans2); } } } int main(){ cin >> n >> k; for(i=0;i<100000;i++){ for(j=0;j<=100:j++){ dp[i][j] = -1; } } if(k >= n){ cin >> a; if(a == 1){ p(0); }else{ p(1); } return 0; }else{ for(i=0;i<n;i++){ cin >> x[i]; } if(x[0] != 1){ ans++; x[0] = 1; } for(i=1;i<n;i++){ G[x[i]].pb(i+1); } p(dfs(1,-1,0) + ans); } return 0; }
a.cc: In function 'int main()': a.cc:128:17: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions] 128 | for(j=0;j<=100:j++){ | ^ a.cc:128:23: error: expected ';' before ':' token 128 | for(j=0;j<=100:j++){ | ^ | ; a.cc:131:5: error: expected primary-expression before '}' token 131 | } | ^ a.cc:130:10: error: expected ';' before '}' token 130 | } | ^ | ; 131 | } | ~ a.cc:131:5: error: expected primary-expression before '}' token 131 | } | ^ a.cc:130:10: error: expected ')' before '}' token 130 | } | ^ | ) 131 | } | ~ a.cc:128:12: note: to match this '(' 128 | for(j=0;j<=100:j++){ | ^ a.cc:131:5: error: expected primary-expression before '}' token 131 | } | ^
s406309433
p04008
C++
st[dep[x]].push_back(x); for (int p=now[x];p;p=pre[p]) { int child=son[p]; fa[child]=x;dep[child]=dep[x]+1; dfs(child); } } void solve(int x) { for (int i=1;i<=k;i++) { if (vis[x]) return; vis[x]=1; x=fa[x]; } ans+=(x!=1); } int main() { n=read(),k=read(); int x=read();if (x!=1) ans=1; for (int i=2;i<=n;i++) { int f=read(); add(f,i); } dfs(1); vis[1]=1; for (int i=n;i;i--) for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) solve(*it); printf("%d\n",ans); return 0; }
a.cc:1:5: error: 'st' does not name a type 1 | st[dep[x]].push_back(x); | ^~ a.cc:2:5: error: expected unqualified-id before 'for' 2 | for (int p=now[x];p;p=pre[p]) | ^~~ a.cc:2:23: error: 'p' does not name a type 2 | for (int p=now[x];p;p=pre[p]) | ^ a.cc:2:25: error: 'p' does not name a type 2 | for (int p=now[x];p;p=pre[p]) | ^ a.cc:8:1: error: expected declaration before '}' token 8 | } | ^ a.cc: In function 'void solve(int)': a.cc:12:21: error: 'k' was not declared in this scope 12 | for (int i=1;i<=k;i++) | ^ a.cc:14:17: error: 'vis' was not declared in this scope 14 | if (vis[x]) return; | ^~~ a.cc:15:13: error: 'vis' was not declared in this scope 15 | vis[x]=1; | ^~~ a.cc:16:15: error: 'fa' was not declared in this scope 16 | x=fa[x]; | ^~ a.cc:18:5: error: 'ans' was not declared in this scope 18 | ans+=(x!=1); | ^~~ a.cc: In function 'int main()': a.cc:23:5: error: 'n' was not declared in this scope 23 | n=read(),k=read(); | ^ a.cc:23:7: error: 'read' was not declared in this scope 23 | n=read(),k=read(); | ^~~~ a.cc:23:14: error: 'k' was not declared in this scope 23 | n=read(),k=read(); | ^ a.cc:24:28: error: 'ans' was not declared in this scope 24 | int x=read();if (x!=1) ans=1; | ^~~ a.cc:28:13: error: 'add' was not declared in this scope 28 | add(f,i); | ^~~ a.cc:30:5: error: 'dfs' was not declared in this scope 30 | dfs(1); | ^~~ a.cc:31:5: error: 'vis' was not declared in this scope 31 | vis[1]=1; | ^~~ a.cc:33:14: error: 'vector' was not declared in this scope 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~~~~~ a.cc:33:21: error: expected primary-expression before 'int' 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~~ a.cc:33:53: error: 'it' was not declared in this scope; did you mean 'i'? 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~ | i a.cc:33:57: error: 'st' was not declared in this scope; did you mean 'std'? 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~ | std a.cc:35:19: error: 'ans' was not declared in this scope 35 | printf("%d\n",ans); | ^~~ a.cc:35:5: error: 'printf' was not declared in this scope 35 | printf("%d\n",ans); | ^~~~~~ a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' +++ |+#include <cstdio> 1 | st[dep[x]].push_back(x);
s187890892
p04008
C++
st[dep[x]].push_back(x); for (int p=now[x];p;p=pre[p]) { int child=son[p]; fa[child]=x;dep[child]=dep[x]+1; dfs(child); } } void solve(int x) { for (int i=1;i<=k;i++) { if (vis[x]) return; vis[x]=1; x=fa[x]; } ans+=(x!=1); } int main() { n=read(),k=read(); int x=read();if (x!=1) ans=1; for (int i=2;i<=n;i++) { int f=read(); add(f,i); } dfs(1); vis[1]=1; for (int i=n;i;i--) for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) solve(*it); printf("%d\n",ans); return 0; }
a.cc:1:5: error: 'st' does not name a type 1 | st[dep[x]].push_back(x); | ^~ a.cc:2:5: error: expected unqualified-id before 'for' 2 | for (int p=now[x];p;p=pre[p]) | ^~~ a.cc:2:23: error: 'p' does not name a type 2 | for (int p=now[x];p;p=pre[p]) | ^ a.cc:2:25: error: 'p' does not name a type 2 | for (int p=now[x];p;p=pre[p]) | ^ a.cc:8:1: error: expected declaration before '}' token 8 | } | ^ a.cc: In function 'void solve(int)': a.cc:12:21: error: 'k' was not declared in this scope 12 | for (int i=1;i<=k;i++) | ^ a.cc:14:17: error: 'vis' was not declared in this scope 14 | if (vis[x]) return; | ^~~ a.cc:15:13: error: 'vis' was not declared in this scope 15 | vis[x]=1; | ^~~ a.cc:16:15: error: 'fa' was not declared in this scope 16 | x=fa[x]; | ^~ a.cc:18:5: error: 'ans' was not declared in this scope 18 | ans+=(x!=1); | ^~~ a.cc: In function 'int main()': a.cc:23:5: error: 'n' was not declared in this scope 23 | n=read(),k=read(); | ^ a.cc:23:7: error: 'read' was not declared in this scope 23 | n=read(),k=read(); | ^~~~ a.cc:23:14: error: 'k' was not declared in this scope 23 | n=read(),k=read(); | ^ a.cc:24:28: error: 'ans' was not declared in this scope 24 | int x=read();if (x!=1) ans=1; | ^~~ a.cc:28:13: error: 'add' was not declared in this scope 28 | add(f,i); | ^~~ a.cc:30:5: error: 'dfs' was not declared in this scope 30 | dfs(1); | ^~~ a.cc:31:5: error: 'vis' was not declared in this scope 31 | vis[1]=1; | ^~~ a.cc:33:14: error: 'vector' was not declared in this scope 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~~~~~ a.cc:33:21: error: expected primary-expression before 'int' 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~~ a.cc:33:53: error: 'it' was not declared in this scope; did you mean 'i'? 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~ | i a.cc:33:57: error: 'st' was not declared in this scope; did you mean 'std'? 33 | for (vector<int>::iterator it=st[i].begin();it!=st[i].end();it++) | ^~ | std a.cc:35:19: error: 'ans' was not declared in this scope 35 | printf("%d\n",ans); | ^~~ a.cc:35:5: error: 'printf' was not declared in this scope 35 | printf("%d\n",ans); | ^~~~~~ a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' +++ |+#include <cstdio> 1 | st[dep[x]].push_back(x);
s806990713
p04008
C++
#include <bits/stdc++.h> typedef long long ll; const int INF = 1e9,MOD = 1e9+7,ohara = 1e6; const ll LINF = 1e18; using namespace std; #define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++) #define rrep(i,a,b) for(ll i=(a);i<(b);i++) #define rrrep(i,a,b) for(ll i=(a);i>=(b);i--) #define all(v) (v).begin(), (v).end() #define pb(q) push_back(q) #define Size(n) (n).size() #define Cout(x) cout<<(x)<<endl ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k; int dy[]={1,0,-1,0}; int dx[]={0,1,0,-1}; //int dy[]={-1,0,1,-1,1,-1,0,1}; //int dx[]={-1,-1,-1,0,0,1,1,1}; string alph("abcdefghijklmnopqrstuvwxyz"),s; bool fl,visited[ohara]; struct edge{int to,cost;}; vector<ll> g[ohara]; //-------------------------↓↓↓↓↓↓------------------------ void dfs(ll now,ll depth){ //if(depth>k+1)return; if(visited[now])return; //cout<<"now "<<now<<" depth "<<depth<<"\n"; visited[now]=true; if(depth==k&&a[now]!=0)ans++,depth=1; if(depth==k)ans++,depth=1; rep(i,Size(g[now])){ ll to=g[now][i]; dfs(to,depth+1); } return; } int main(void){ cin.tie(0); ios::sync_with_stdio(false); cin>>n>>k; rep(i,n){ cin>>a[i]; if(i==0&&a[i]!=1)ans=1; if(i==a[ohara]-1)continue; if(i==0)continue; a[i]--; g[a[i]].push_back(i); } dfs(0,0); Cout(ans); return 0; }
a.cc: In function 'void dfs(ll, ll)': a.cc:32:19: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript 32 | if(depth==k&&a[now]!=0)ans++,depth=1; | ^ a.cc: In function 'int main()': a.cc:47:15: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript 47 | cin>>a[i]; | ^ a.cc:48:19: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript 48 | if(i==0&&a[i]!=1)ans=1; | ^ a.cc:49:16: error: invalid types 'll {aka long long int}[const int]' for array subscript 49 | if(i==a[ohara]-1)continue; | ^ a.cc:51:10: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript 51 | a[i]--; | ^ a.cc:52:12: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript 52 | g[a[i]].push_back(i); | ^
s556503210
p04008
C++
#include <bits/stdc++.h> typedef long long ll; const int INF = 1e9,MOD = 1e9+7,ohara = 1e6; const ll LINF = 1e18; using namespace std; #define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++) #define rrep(i,a,b) for(ll i=(a);i<(b);i++) #define rrrep(i,a,b) for(ll i=(a);i>=(b);i--) #define all(v) (v).begin(), (v).end() #define pb(q) push_back(q) #define Size(n) (n).size() #define Cout(x) cout<<(x)<<endl ll n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k; int dy[]={1,0,-1,0}; int dx[]={0,1,0,-1}; //int dy[]={-1,0,1,-1,1,-1,0,1}; //int dx[]={-1,-1,-1,0,0,1,1,1}; string alph("abcdefghijklmnopqrstuvwxyz"),s; bool fl,visited[ohara]; struct edge{int to,cost;}; vector<ll> g[ohara]; //-------------------------↓↓↓↓↓↓------------------------ void dfs(ll now,ll depth){ //if(depth>k+1)return; if(visited[now])return; //cout<<"now "<<now<<" depth "<<depth<<"\n"; visited[now]=true; if(depth==k&&a[now]!=0)ans++,depth=1; if(depth==k)ans++,depth=1; rep(i,Size(g[now])){ ll to=g[now][i]; dfs(to,depth+1); } return; } int main(void){ cin.tie(0); ios::sync_with_stdio(false); cin>>n>>k; rep(i,n){ cin>>a; if(i==0&&a!=1)ans=1; if(i==a-1)continue; if(i==0)continue; a--; g[a].push_back(i); } dfs(0,0); Cout(ans); return 0; }
a.cc: In function 'void dfs(ll, ll)': a.cc:32:19: error: invalid types 'll {aka long long int}[ll {aka long long int}]' for array subscript 32 | if(depth==k&&a[now]!=0)ans++,depth=1; | ^
s434914330
p04008
C++
#include<bits/stdc++.h> vector<int> v[1<<17];int n,k,a,y,t,i; int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;} int main(){std::cin>>n>>k>>y;for(a=(y!=1);std::cin>>y;v[y-1].push_back(++i));s(0,0);std::cout<<a;}
a.cc:2:1: error: 'vector' does not name a type 2 | vector<int> v[1<<17];int n,k,a,y,t,i; | ^~~~~~ a.cc: In function 'int s(int, int)': a.cc:3:33: error: found ':' in nested-name-specifier, expected '::' 3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;} | ^ | :: a.cc:3:32: error: 't' is not a class, namespace, or enumeration 3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;} | ^ a.cc:3:68: error: expected primary-expression before 'return' 3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;} | ^~~~~~ a.cc:3:68: error: expected ')' before 'return' 3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;} | ~ ^~~~~~ | ) a.cc: In function 'int main()': a.cc:4:55: error: 'v' was not declared in this scope 4 | int main(){std::cin>>n>>k>>y;for(a=(y!=1);std::cin>>y;v[y-1].push_back(++i));s(0,0);std::cout<<a;} | ^ a.cc: In function 'int s(int, int)': a.cc:3:79: warning: control reaches end of non-void function [-Wreturn-type] 3 | int s(int x,int p){int r=0;for(t:v[x])r=max(r,s(t,x));a+=++r>=k&&p;return r%k;} | ^
s757567487
p04008
C++
#include<bits/stdc++.h> using namespace std; vector<int> v[1e6];int n,k,a,y,i=1; int s(int x,int p=0){int r=0;for(int to:v[x])r=max(r,s(to,x));if(++r>=k&&p)a++,r=0;return r;} int main(){cin>>n>>k>>y;if(y!=1)a++;for(;i<n;i++){cin>>y;v[y-1].push_back(i);}s(0);cout<<a;}
a.cc:3:15: error: conversion from 'double' to 'long unsigned int' in a converted constant expression 3 | vector<int> v[1e6];int n,k,a,y,i=1; | ^~~ a.cc:3:15: error: could not convert '1.0e+6' from 'double' to 'long unsigned int' 3 | vector<int> v[1e6];int n,k,a,y,i=1; | ^~~ | | | double a.cc:3:15: error: size of array 'v' has non-integral type 'double'
s387196985
p04008
C++
#include<bits/stdc++.h> using namespace std; vector<int> v[101010]; int n,k,a,y,i=1; int s(int x,int p=0){ int r=0; for(auto to:v[x])r=max(r,s(to,x)); if(++r>=k&&p)a++,r=0; return r; } int main(){ cin>>n>>k>>y; if(y!=1)a++; for(;i<n;i++){ cin>>y; v[x-1].push_back(i); } s(0); puts(a); }
a.cc: In function 'int main()': a.cc:17:11: error: 'x' was not declared in this scope 17 | v[x-1].push_back(i); | ^ a.cc:20:10: error: invalid conversion from 'int' to 'const char*' [-fpermissive] 20 | puts(a); | ^ | | | int In file included from /usr/include/c++/14/cstdio:42, from /usr/include/c++/14/ext/string_conversions.h:45, from /usr/include/c++/14/bits/basic_string.h:4154, 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, from a.cc:1: /usr/include/stdio.h:714:30: note: initializing argument 1 of 'int puts(const char*)' 714 | extern int puts (const char *__s); | ~~~~~~~~~~~~^~~
s957603171
p04008
C++
#pragma GCC optimize(2) #include <iostream> #include <stdio.h> #include <bits/stdc++.h> typedef long long ll; const int MAXN = 1e5 + 5; const int mod = 1e9 + 7; using namespace std; int cot[MAXN]; int nex[MAXN]; int deq[MAXN]; int main() { int n, k; cin >> n >> k; int ans = 0; for(int i = 1; i <= n; i++) { int x; scanf("%d",&); if(i == 1 && x != 1) { ans++; continue; } else { nex[i] = x; cot[x]++; } } queue<int>Q; int t = 0, h = 0; for(int i = 2; i <= n; i++) if(!cot[i]) Q.push(i); while(!Q.empty()) { int u = Q.front(); Q.pop(); if(u == 1) break; if( nex[u] != 1 && deq[u] == (k - 1) ) ans++; else deq[nex[u]] = max(deq[nex[u]], deq[u] + 1); cot[ nex[u] ]--; if(!cot[ nex[u] ]) Q.push( nex[u]); } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:18:21: error: expected primary-expression before ')' token 18 | scanf("%d",&); | ^
s744183184
p04008
C++
#pramga GCC optimize(2) #include <iostream> #include <stdio.h> #include <bits/stdc++.h> typedef long long ll; const int MAXN = 1e5 + 5; const int mod = 1e9 + 7; using namespace std; int cot[MAXN]; int nex[MAXN]; int deq[MAXN]; int main() { int n, k; cin >> n >> k; int ans = 0; for(int i = 1; i <= n; i++) { int x; scanf("%d",&); if(i == 1 && x != 1) { ans++; continue; } else { nex[i] = x; cot[x]++; } } queue<int>Q; int t = 0, h = 0; for(int i = 2; i <= n; i++) if(!cot[i]) Q.push(i); while(!Q.empty()) { int u = Q.front(); Q.pop(); if(u == 1) break; if( nex[u] != 1 && deq[u] == (k - 1) ) ans++; else deq[nex[u]] = max(deq[nex[u]], deq[u] + 1); cot[ nex[u] ]--; if(!cot[ nex[u] ]) Q.push( nex[u]); } cout << ans << endl; return 0; }
a.cc:1:2: error: invalid preprocessing directive #pramga; did you mean #pragma? 1 | #pramga GCC optimize(2) | ^~~~~~ | pragma a.cc: In function 'int main()': a.cc:18:21: error: expected primary-expression before ')' token 18 | scanf("%d",&); | ^
s395471203
p04008
C++
#include <iostream> #include <vector> #include <algorithm> #include <stack> #include <utility> #define MAX_V 100010 using namespace std; vector<int> G[MAX_V]; vector<pair<int,int>> toi; stack<int> st; bool used[MAX_V]; int d[MAX_V],a[MAX_V],c; void dfs(int s){ used[s] = true; st.push(s); while(!st.empty()){ int e = st.top(); st.pop(); for(int i=0;i<G[e].size();i++){ if(!used[G[e][i]]){ used[G[e][i]] = true; d[G[e][i]] = d[e]+1; st.push(G[e][i]); } } } } void dfs1(int s){ used[s] =false; st.push(s); while(!st.empty()){ int e = st.top(); st.pop(); for(int i=0;i<G[e].size();i++){ if(used[G[e][i]]){ used[G[e][i]] = false; st.push(G[e][i]); } } } } int main(){ int i,j,k,ans=0,cnt,x,y; cin >> V >> k; cin >> i; if(i!=1){ ans++; } for(i=1;i<V;i++){ cin >> a[i]; a[i]--; G[a[i]].push_back(i); } for(i=0;i<V;i++){ G[i].push_back(-1); used[i] = false; d[i] = 0; } dfs(0); for(i=0;i<V;i++){ if(d[i]>k){ toi.push_back(make_pair(d[i],i)); } } sort(toi.begin(),toi.end()); for(i=toi.size()-1;i>=0;i--){ if(used[toi[i].second]){ ans ++; cnt = 0; x = toi[i].second; while(cnt<k-1){ cnt++; y = a[x]; x = y; } dfs1(x); } } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:49:16: error: 'V' was not declared in this scope 49 | cin >> V >> k; | ^
s428354231
p04008
C++
#include<cstdio> #include<cstring> #include<algorithm> const int N=1e5+10; int n,k,sum=0,count[N],q[N],h=1,t=0,fa[N],ll[N]; int read(){ int f=1,ans=0;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+c-48;c=getchar();} return ans*f; } int main(){ n=read();k=read(); int a=read();if(a!=1)sum++; for(int i=2;i<=n;i++){ a=read();fa[i]=a;count[a]++; } for(int i=2;i<=n;i++)if(!count[i])q[++t]=i; while(h<=t){ int x=q[h];h++; if(x==1)break; if(fa[x]!=1&&ll[x]==k-1)sum++; else ll[fa[x]]=std::max(ll[fa[x]],ll[x]+1); count[fa[x]]--; if(!count[fa[x]])q[++t]=fa[x]; } printf("%d\n",sum); return 0; } agc004 D
a.cc:31:1: error: 'agc004' does not name a type 31 | agc004 D | ^~~~~~
s185462970
p04008
C++
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <math.h> using namespace std; const int MAXN = 1e5 + 10; int N, K; vector<int> E[MAXN]; int ans; inline int Dfs(int x) { int res = 1, d; for(register int i : E[x]) (d = Dfs(i)) == K ? ++ans : res = max(res, d + 1); return res; } int main() { register int i; int x; scanf("%d%d", &N, &K); for(i = 1; i <= N; ++i) scanf("%d", &x), (i > 1) ? E[x].push_back(i), 0 : ans += x != 1; for(register int i : E[1]) Dfs(i); printf("%d\n", ans); return 0; }
a.cc:10:1: error: 'vector' does not name a type 10 | vector<int> E[MAXN]; | ^~~~~~ a.cc: In function 'int Dfs(int)': a.cc:15:30: error: 'E' was not declared in this scope 15 | for(register int i : E[x]) | ^ a.cc:15:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 15 | for(register int i : E[x]) | ^ a.cc: In function 'int main()': a.cc:21:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 21 | register int i; int x; | ^ a.cc:25:27: error: 'E' was not declared in this scope 25 | (i > 1) ? E[x].push_back(i), 0 : ans += x != 1; | ^ a.cc:26:30: error: 'E' was not declared in this scope 26 | for(register int i : E[1]) Dfs(i); | ^ a.cc:26:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 26 | for(register int i : E[1]) Dfs(i); | ^
s580985819
p04008
C++
# include <bits/stdc++.h> using namespace std; # define REP(i, a, b) for(int i = a; i <= b; ++ i) # define CLR(i, a) memset(i, a, sizeof(i)) # define REPD(i, a, b) for(int i = a; i >= b; -- i) # define REPG(i, h, x) for(int i = h[x], v; ~i; i = edge[i].next) const int N = 1e5 + 5; int n, k; int head[N], cnt; struct qwq { int v, next; } edge[N << 1]; inline void add(int u, int v) { edge[++ cnt] = (qwq) { v, head[u] }, head[u] = cnt; } int f[N], ans; int dfs(int x, int fa) { int why = 1; REPG(i, head, x) if((v = edge[i].v) != fa) { why = max(dfs(v, x) + 1, why); } if(why == k && fa != 1) { ++ ans; return why = 0; } } int main() { CLR(head, -1); scanf("%d%d", &n, &k); REP(i, 1, n) scanf("%d", &a[i]); REP(i, 2, n) add(a[i], i); dfs(1, 0); printf("%d\n", a[1] == 1 ? ans : ans + 1); return 0; }
a.cc: In function 'int main()': a.cc:30:35: error: 'a' was not declared in this scope 30 | REP(i, 1, n) scanf("%d", &a[i]); | ^ a.cc:31:26: error: 'a' was not declared in this scope 31 | REP(i, 2, n) add(a[i], i); | ^ a.cc:33:24: error: 'a' was not declared in this scope 33 | printf("%d\n", a[1] == 1 ? ans : ans + 1); | ^ a.cc: In function 'int dfs(int, int)': a.cc:25:1: warning: control reaches end of non-void function [-Wreturn-type] 25 | } | ^
s420712236
p04008
C++
#include<bits/stdc++.h> using namespace std; const int N=2e5; int m,ans; int head[N],nxt[N]; inline void dfs(int k,int s) { if (s>m) s=1,ans++; for (int i=head[k];i;i=nxt[i]) dfs(i,s+1); } int main() { int n=gi(),i,k;m=gi(); ans=gi()!=1; for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i; dfs(1,0); printf("%d\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:13:15: error: 'gi' was not declared in this scope 13 | int n=gi(),i,k;m=gi(); | ^~ a.cc:15:14: error: 'i' was not declared in this scope 15 | for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i; | ^ a.cc:15:40: error: 'k' was not declared in this scope 15 | for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i; | ^
s971448668
p04008
C++
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() #define LL long long using namespace std; int N,K; int a[100000]; int ans = 0; int rank[100000]; int DFS(int v){ if(rank[v]>=0)return rank[v]; int res = rank[a[v]]+1; if(res>K)ans++,res=1; return rank[v] = res; } int main(){ cin>>N>>K; REP(i,N)cin>>a[i],a[i]--; fill_n(rank,100000,-1); if(a[0]!=0)ans++,a[0]=0,rank[0]=0; REP(i,N)DFS(i); cout<<ans<<endl; return 0; }
a.cc: In function 'int DFS(int)': a.cc:16:8: error: reference to 'rank' is ambiguous 16 | if(rank[v]>=0)return rank[v]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, 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:2: /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [100000]' 13 | int rank[100000]; | ^~~~ a.cc:16:26: error: reference to 'rank' is ambiguous 16 | if(rank[v]>=0)return rank[v]; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [100000]' 13 | int rank[100000]; | ^~~~ a.cc:17:15: error: reference to 'rank' is ambiguous 17 | int res = rank[a[v]]+1; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [100000]' 13 | int rank[100000]; | ^~~~ a.cc:19:12: error: reference to 'rank' is ambiguous 19 | return rank[v] = res; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [100000]' 13 | int rank[100000]; | ^~~~ a.cc: In function 'int main()': a.cc:26:12: error: reference to 'rank' is ambiguous 26 | fill_n(rank,100000,-1); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [100000]' 13 | int rank[100000]; | ^~~~ a.cc:27:29: error: reference to 'rank' is ambiguous 27 | if(a[0]!=0)ans++,a[0]=0,rank[0]=0; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [100000]' 13 | int rank[100000]; | ^~~~
s328212953
p04008
C++
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair void dfs(int no,int d,int k); vector<int> ed[100001]; int visit[100001]; int ans=0; int main(){ int i,j; int n,k; cin>>n>>k; int a[n+1]; for(i=1;i<=n;i++) {cin>>a[i]; if(i==1){ if(a[1]!=1) {a[1]=1; ans++; } continue; } else ed[a[i]].pb(i); } if(k<=1e5){ dfs(1,0,k); } cout<<ans<<endl; return 0; } void dfs(int no,int d,int k){ visit[no]=1; int i; if(d>k) { ans++; d=1; } for(i=0;i<ed[no].size();i++){ if(visit[ed[no[i]]==0) dfs(ed[no][i],d+1,k); } }
a.cc: In function 'void dfs(int, int, int)': a.cc:40:1: error: reference to 'visit' is ambiguous 40 | visit[no]=1; | ^~~~~ 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:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:8:5: note: 'int visit [100001]' 8 | int visit[100001]; | ^~~~~ a.cc:49:4: error: reference to 'visit' is ambiguous 49 | if(visit[ed[no[i]]==0) | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:8:5: note: 'int visit [100001]' 8 | int visit[100001]; | ^~~~~ a.cc:49:15: error: invalid types 'int[int]' for array subscript 49 | if(visit[ed[no[i]]==0) | ^ a.cc:49:22: error: expected ']' before ')' token 49 | if(visit[ed[no[i]]==0) | ^ | ]
s719303086
p04008
C++
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const ll MOD = 1000000007; int N, K; int ans; vector<vector<int>> rev; // int dfs(int v, int prev){ // int depth = 0; // for(int to : rev[v]){ // if(to == prev) continue; // depth = max(depth, 1 + dfs(to, v)); // } // if(depth == K-1 && prev != 0){ // ans++; // return 0; // } // return depth; // } int dfs(int pos, int pre) { int e = 0; for (int i : rev[pos]) { if (i == pre) continue; e = max(e, dfs(i, pos)); } if (e == m - 1) { if(pre != 0) ans++; return 0; } return e + 1; } int main(){ cin >> N >> K; ans = 0; rev.assign(N, {}); for(int i=0;i<N;i++){ int a; cin >> a; if(i == 0){ ans += a != 1 ? 1 : 0; }else{ rev[a-1].push_back(i); } } for (int i : rev[0]) dfs(i, 0); cout << ans << endl; return 0; }
a.cc: In function 'int dfs(int, int)': a.cc:30:18: error: 'm' was not declared in this scope 30 | if (e == m - 1) { | ^
s394317410
p04008
C++
#include <set> #include <map> #include <queue> #include <ctime> #include <cmath> #include <cstdio> #include <vector> #include <string> #include <cctype> #include <bitset> #include <cstring> #include <cstdlib> #include <utility> #include <iostream> #include <algorithm> #define REP(i,a,b) for(int i=(a);i<=(b);i++) #define PER(i,a,b) for(int i=(a);i>=(b);i--) #define RVC(i,S) for(int i=0;i<(S).size();i++) #define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next) using namespace std; typedef long long LL; typedef pair<int,int> pii; template<class T> inline void read(T& num) { bool start=false,neg=false; char c; num=0; while((c=getchar())!=EOF) { if(c=='-') start=neg=true; else if(c>='0' && c<='9') { start=true; num=num*10+c-'0'; } else if(start) break; } if(neg) num=-num; } /*============ Header Template ============*/ struct edge { int next,to; }; const int maxn=(int)(1e5)+5; int a[maxn]; int fr[maxn]; edge e[maxn<<1]; int n,m,tote=0; inline void addone(int u,int v) { ++tote; e[tote].next=fr[u];fr[u]=tote;e[tote].to=v; } inline void addedge(int u,int v) { addone(u,v);addone(v,u); } int res; void dfs(int x,int f,int d) { RAL(i,x) if(ds[e[i].to]==ds[x]+1) { if(d>=m) ++res,dfs(e[i].to,x,1); else dfs(e[i].to,x,d+1); } } void bfs(int s) { memset(ds,-1,sizeof(ds)); Q.push(1);ds[1]=0; while(!Q.empty()) { int x=Q.front();Q.pop(); RAL(i,x) if(ds[e[i].to]<0) ds[e[i].to]=ds[x]+1,Q.push(e[i].to); } } int main() { read(n);read(m); REP(i,1,n) read(a[i]); res=(a[1]!=1); memset(fr,-1,sizeof(fr)); REP(i,2,n) addedge(a[i],i); bfs(1);dfs(1,0,0); printf("%d\n",res); return 0; }
a.cc: In function 'void dfs(int, int, int)': a.cc:61:17: error: 'ds' was not declared in this scope; did you mean 'd'? 61 | RAL(i,x) if(ds[e[i].to]==ds[x]+1) { | ^~ | d a.cc: In function 'void bfs(int)': a.cc:68:12: error: 'ds' was not declared in this scope; did you mean 's'? 68 | memset(ds,-1,sizeof(ds)); | ^~ | s a.cc:69:5: error: 'Q' was not declared in this scope 69 | Q.push(1);ds[1]=0; | ^
s317924463
p04008
C++
#include<iostream> #include<queue> #include<functional> using namespace std; int n, k, a[200000], dist[200000], dist2[200000], cnt, r[200000]; vector<int>G[200000], H[200000], U[200000]; int T; queue<pair<int, int>>Q; vector<pair<int, int>>V; void bfs1() { for (int i = 1; i <= n; i++)dist2[i] = 999999999; queue<int>R; R.push(1); dist2[1] = 0; while (!R.empty()) { int a1 = R.front(); R.pop(); for (int i = 0; i < H[a1].size(); i++) { if (dist2[H[a1][i]] > dist2[a1] + 1) { dist2[H[a1][i]] = dist2[a1] + 1; R.push(H[a1][i]); } } } } void sorts() { for (int i = 1; i <= n; i++)dist[i] = -99999999; for (int i = 1; i <= n; i++) { if (r[i] == 0)V.push_back(make_pair(dist2[i], i)); } sort(V.begin(), V.end(), greater<pair<int, int>>()); int maxd = V[0].first; while (T < V.size() && V[T].first == maxd) { Q.push(make_pair(V[T].second, maxd)); dist[V[T].second] = 0; T++; } } void bfs3() { while (!Q.empty()) { int a1 = Q.front().first, a2 = Q.front().second; Q.pop(); while (T < V.size() && V[T].first == a2 - 1) { Q.push(make_pair(V[T].second, a2 - 1)); dist[V[T].second] = 0; T++; } for (int i = 0; i < G[a1].size(); i++) { int DD = dist[a1] + 1; if (DD == k && G[a1][i] != 1) { DD = 0; cnt++; } if (dist[G[a1][i]] < DD) { dist[G[a1][i]] = DD; Q.push(make_pair(G[a1][i], a2 - 1)); } } } } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i != 1) { G[i].push_back(a[i]); H[a[i]].push_back(i); r[a[i]]++; } } if (a[1] != 1) { cnt++; a[1] = 1; } bfs1(); sorts(); bfs3(); cout << cnt << endl; return 0; }
a.cc: In function 'void sorts()': a.cc:24:9: error: 'sort' was not declared in this scope; did you mean 'sorts'? 24 | sort(V.begin(), V.end(), greater<pair<int, int>>()); | ^~~~ | sorts
s915224147
p04008
C++
#include <stdlib.h> #include <stdio.h> typedef int bool; #define true 1 #define false 0 int main(int argc, char* argv[]){ int N, K; scanf("%d %d", &N, &K); int a[N]; int i,j; for(i=0; i<N; ++i){ scanf("%d",&a[i]); } int ans = 0; if(a[0] != 1){ a[0] = 1; ++ans; } int count[N]; bool counted[N]; for(i=0; i<N; ++i){ counted[i] = false; } count[0] = 0; counted[0] = true; bool finish = false; while(!finish){ finish = true; for(i=0; i<N; ++i){ if(!counted[i]){ if(counted[a[i]-1]){ count[i] = count[a[i]-1] + 1; counted[i] = true; }else{ finish = false; } } } } //for(i=0; i<N; ++i){ // printf("%d\n",count[i]); //} bool connected[N]; int maxcount = 0; int maxi = 0; bool comp = true; for(i=0; i<N; ++i){ connected[i] = false; if(count[i] > K){ comp = false; } if(count[i] > maxcount){ maxcount = count[i]; maxi = i; } } while(!comp){ int p = maxi; for(i=0; i<K-1; ++i){ p = a[p] - 1; } a[p] = 1; connected[p] = true; ++ans; finish = false; while(!finish){ finish = true; for(i=0; i<N; ++i){ if(!connected[i]){ if(connected[a[i]-1]){ connected[i] = true; finish = false; } } } } maxcount = 0; maxi = 0; for(i=0; i<N; ++i){ if(!connected[i]){ if(count[i] > maxcount){ maxcount = count[i]; maxi = i; } } } if(maxcount <= K){ comp = true; } } printf("%d\n",ans); return 0; }
a.cc:4:13: error: redeclaration of C++ built-in type 'bool' [-fpermissive] 4 | typedef int bool; | ^~~~
s711121952
p04008
Java
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main_Other { /** * 整数K */ private static int K; /** * ある町へ転送するテレポータが設置されている町のリスト */ private static List<List<Integer>> vec = new ArrayList<>(); /** * 転送先を変えなければならないテレポータの数 */ private static int ans = 0; public static void main(String args[]) { //スタックサイズ2^24で処理を行う new Thread(null, () -> { //try-with-resources文(カッコ内で宣言した変数はtry句を抜けると自動的に閉じられる) try (Scanner sc = new Scanner(System.in)) { int n = sc.nextInt(); K = sc.nextInt(); for (int i = 0; i < n; i++) { vec.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { int a = sc.nextInt() - 1; if (i != 0) { vec.get(a).add(i); } else if (a != 0) { ans++; } } } dfs(0, 0); System.out.println(ans); }, "", 1 << 24).start(); } /** * 転送回数を算出する * * @param v 着目する町 * @param pre 1つ前の町 * @return 転送回数 */ private static int dfs(int v, int pre) { int height = 0; //拡張for文(リストや配列から要素を1つずつ取り出す) for (int j : vec.get(v)) { height = Math.max(height, dfs(j, v)); } if (pre != 0 && height == K - 1) { height = 0; ans++; } else { height++; } return height; } }
Main.java:5: error: class Main_Other is public, should be declared in a file named Main_Other.java public class Main_Other { ^ 1 error
s914737665
p04008
Java
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { private static long K; private static List<List<Long>> vec; private static int ans; public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); K = sc.nextLong(); ans = 0; vec = new ArrayList<>(); for (int i = 0; i < n; i++) { vec.add(new ArrayList<>()); } for (long i = 0; i < n; i++) { int a = sc.nextInt() - 1; if (i != 0) { vec.get(a).add(i); } else if (a != 0) { ans++; } } dfs(0, 0); System.out.println(ans); } private static long dfs(long v, int pre) { long height = 0; for (long j : vec.get((int)v)) { height = Math.max(height, dfs(j, v)); } if (pre != 0 && height == K - 1) { height = 0; ans++; } else { height++; } return height; } }
Main.java:34: error: incompatible types: possible lossy conversion from long to int height = Math.max(height, dfs(j, v)); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error
s945193996
p04008
Java
import ru.ifmo.niyaz.io.FastScannerTokenizer; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.IOException; import java.util.*; import java.io.InputStreamReader; import java.io.Writer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Niyaz Nigmatullin */ public class Main { public static void main(String[] args) { new Thread(null, new Runnable() { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScannerTokenizer in = new FastScannerTokenizer(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } }, "", 1 << 27).start(); } static class TaskD { static List<Integer>[] edges; static int[] kill; static int[] left; static int k; public void solve(int testNumber, FastScannerTokenizer in, FastPrinter out) { int n = in.nextInt(); k = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt() - 1; int ans = 0; if (a[0] != 0) { a[0] = 0; ans++; } edges = new List[n]; for (int i = 0; i < n; i++) { edges[i] = new ArrayList<>(); } for (int i = 1; i < n; i++) { edges[a[i]].add(i); } kill = new int[n]; left = new int[n]; dfs(0); out.println(kill[0] + ans); } static void dfs(int v) { kill[v] = 0; left[v] = 0; for (int it = 0; it < edges[v].size(); it++) { int to = edges[v].get(it); dfs(to); kill[v] += kill[to]; if (left[to] == k - 1 && v != 0) { kill[v]++; } else { left[v] = Math.max(left[v], left[to] + 1); } } } } static class FastScannerTokenizer { BufferedReader br; StringTokenizer st; IOException happened; public FastScannerTokenizer(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public boolean hasNext() { while (st == null || !st.hasMoreTokens()) { String line; try { line = br.readLine(); } catch (IOException e) { happened = e; return false; } if (line == null) { return false; } st = new StringTokenizer(line); } return true; } // public String next() { // if (!hasNext()) { // return null; // } // return st.nextToken(); // } public String next() { while (st == null || !st.hasMoreTokens()) { try { String line = br.readLine(); st = new StringTokenizer(line); } catch (IOException e) { happened = e; return null; } } return st.nextToken(); } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { String line = br.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } catch (IOException e) { happened = e; return null; } } return st.nextToken(); } public int indianNextInt() { String e = nextToken(); if (e == null) { return 0; } return Integer.parseInt(e); } public int fastNextInt() { try { int c = br.read(); while (c <= 32 && c >= 0) { c = br.read(); } if (c == -1) { throw new NoSuchElementException(); } int sgn = 1; if (c == '-') { sgn = -1; c = br.read(); } if (c < '0' || c > '9') { throw new NumberFormatException("digit expected " + (char) c + " found"); } int ret = 0; while (c >= '0' && c <= '9') { ret = ret * 10 + c - '0'; c = br.read(); } if (c > 32) { throw new NumberFormatException("space character expected " + (char) c + " found"); } return ret * sgn; } catch (IOException e) { return Integer.MIN_VALUE; } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { if (st != null && st.hasMoreTokens()) { StringBuilder ret = new StringBuilder(); while (st.hasMoreElements()) { ret.append(st.nextElement()); } return ret.toString(); } else { String line = br.readLine(); return line; } } catch (IOException e) { happened = e; return null; } } public void skipLine() { if (st == null || !st.hasMoreElements()) { try { br.readLine(); } catch (IOException e) { happened = e; return; } } else { st = null; } } public int readTimeHM(char delim) { String s = next(); int pos = s.indexOf(delim); if (pos < 0) { throw new NumberFormatException("no delim found"); } return Integer.parseInt(s.substring(0, pos)) * 60 + Integer.parseInt(s.substring(pos + 1)); } public int readTimeHMS(char delim1, char delim2) { String s = next(); int pos = s.indexOf(delim1); if (pos < 0) { throw new NumberFormatException("no delim found"); } int pos2 = s.indexOf(delim2, pos + 1); if (pos2 < 0) { throw new NumberFormatException("no second delim found"); } return Integer.parseInt(s.substring(0, pos)) * 3600 + Integer.parseInt(s.substring(pos + 1, pos2)) * 60 + Integer.parseInt(s.substring(pos2 + 1)); } public int readTimeHMS(char delim) { return readTimeHMS(delim, delim); } } static class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } public FastPrinter(Writer out) { super(out); } } }
Main.java:1: error: package ru.ifmo.niyaz.io does not exist import ru.ifmo.niyaz.io.FastScannerTokenizer; ^ Note: Main.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
s795107876
p04008
C++
#include<iostream> #include<cstdio> #include<vector> using namespace std; typedef long long ll; ll N,K,ans=0; int a[100010]; vector<int> p[100010]; void dfs(ll h,int v) { if (h == K && a[v] != 1) { ans++; h = 0; } for (int i = 0; i < p[v].size(); i++) { dfs(h + 1, p[v][i]); } } int main() { cin >> N >> K; cin >> a[0]; if (a[0] != 1)ans++; for (int i = 1; i < N; i++) { scanf_s("%d", &a[i]); p[a[i]].push_back(i); } dfs(-1, 0); cout << ans << endl; }
a.cc: In function 'int main()': a.cc:25:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'? 25 | scanf_s("%d", &a[i]); | ^~~~~~~ | scanf
s673882193
p04008
Java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Denis Nedelyaev */ public class Main { public static void main(String[] args) throws Exception { OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); AtD solver = new AtD(System.in, out); solver.solve(1); out.close(); } static class AtD { private final PrintWriter out; private List<Integer>[] children; private int maxHeight; private int[] depth; public AtD(InputStream inputStream, PrintWriter out) { in = inputStream; size = 0; this.out = out; } public void solve(int testNumber) throws InterruptedException { int n = nextInt(); maxHeight =nextInt(); int[] parent = new int[n]; for (int i = 0; i < n; i++) { parent[i] = nextInt() - 1; } children = new List[n]; for (int i = 0; i < n; i++) { children[i] = new ArrayList<>(); } for (int i = 1; i < n; i++) { children[parent[i]].add(i); } depth = new int[n]; Thread thread = new Thread(null, () -> calcDepth(0), "solution", 1 << 24); thread.setUncaughtExceptionHandler((t, e) -> { throw new RuntimeException(e); }); thread.start(); thread.join(); int ans = 0; if (parent[0] != 0) { ans++; } for (int v = 1; v < n; v++) { if (parent[v] != 0 && depth[v] == 0) { ans++; } } out.println(ans); } private int calcDepth(int v) { int ans = 0; for (int u : children[v]) { ans = Math.max(ans, calcDepth(u)); } return depth[v] = ans + 1 == maxHeight ? 0 : 1 + ans; } private final InputStream in; private byte[] buffer = new byte[4096]; private int pos = 0; private int size; public FastScanner(InputStream inputStream) throws IOException { in = inputStream; size = 0; } public int nextInt() { int c = skipWhitespace(); int ans = 0; while (c > ' ') { ans *= 10; ans += c - '0'; c = nextChar(); } return ans; } private int skipWhitespace() { while (true) { int c = nextChar(); if (c > ' ' || c == -1) { return c; } } } private int nextChar() { if (pos >= size) { try { size = in.read(buffer); } catch (IOException e) { throw new RuntimeException(e); } if (size <= 0) { return -1; } pos = 0; } return buffer[pos++]; } } }
Main.java:91: error: invalid method declaration; return type required public FastScanner(InputStream inputStream) throws IOException { ^ 1 error
s537869142
p04008
C++
#include <stdio.h> #include <string.h> #include <vector> #include <algorithm> using namespace std; using ll = long long; ll n, k; ll a[123456]; vector<ll>child[123456]; ll rem[123456]; ll ans = 0; ll calcrem(ll v) { if (rem[v] >= 0)return rem[v]; ll ans = 0; if (child[v].size() == 0) { return rem[v] = 0; } else { for (ll to : child[v]) { ans = max(ans, calcrem(to) + 1); } } return rem[v] = ans; } void pulltree(ll v,ll depth) { if (rem[v] == k - 1 && depth != 1 && depth != 0) { ++ans; return; } if (depth == k) { //pull for (ll to : child[v]) { ++ans; pulltree(to, 1); } } else { for (ll to : child[v]) { pulltree(to, depth + 1); } } } ll main() { scanf("%d %d", &n, &k); scanf("%d",a); if (a[0] != 1)ans += 1; for (ll i = 0; i < n - 1; ++i) { scanf("%d", a + i); --a[i]; child[a[i]].push_back(i + 1); } memset(rem, 0xFF, sizeof(rem)); calcrem(0); pulltree(0, 0); printf("%d\n", ans); return 0; }
a.cc:60:1: error: '::main' must return 'int' 60 | ll main() | ^~
s868882833
p04008
C++
#include <bits/stdc++.h> using namespace std; int n, k; int a[100055]; int d[100055]; bool used[100055]; bool in[100055]; vector<int> rg[100055]; int tail[100055]; void dfs(int v, int dep = 0) { d[v] = dep; used[v] = true; for (auto u : rg[v]) { if (used[u]) continue; dfs(u, dep + 1); } } int rdfs(int v) { used[v] = true; int res = 0; for (auto u : rg[v]) { if (!used[u]) { res = max(res, rdfs(u) + 1); } } return res; } int go(int v, int &res) { int ret = 0; for (auto u : rg[v]) { ret = max(ret, go(u, res) + 1); } if (ret + 1 == k) { res++; return 0; } return ret; } int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; rg[a[i]].push_back(i); } dfs(0); bool bad = false; for (int i = 0; i < n; i++) { if (d[i] != k) { bad = true; } } if (!bad) { puts("0"); return 0; } bad = false; for (int i = 0; i < n; i++) { if (d[i] > k) { bad = true; } } if (!bad) { printf("%d\n", a[0] != 0); return 0; } int res = a[0] !+ 0; memset(used, false, sizeof(used)); vector<int> cycle; int cur = 0; while (!used[cur]) { cycle.push_back(cur); used[cur] = in[cur] = true; cur = a[cur]; } cur = 0; reverse(cycle.begin(), cycle.end()); for (auto v : cycle) { cur++; if (v == 0) cur = 0; if (cur > k) { res++; cur = 1; } for (auto u : rg[v]) { if (!in[u]) { tail[v] = max(tail[v], rdfs(u) + 1); } } if (cur + tail[v] > k) { bool flag = false; for (auto u : rg[v]) { if (!in[u]) { if (cur + go(u, res) + 1 > k) { flag = true; } } } if (flag) { res++; cur = 1; } } } printf("%d\n", res); return 0; }
a.cc: In function 'int main()': a.cc:86:24: error: expected ',' or ';' before '!' token 86 | int res = a[0] !+ 0; | ^
s124343408
p04008
C++
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author RiaD */ #include <iostream> #include <fstream> #include <iostream> #include <vector> #include <iterator> #include <string> #include <stdexcept> #ifndef SPCPPL_ASSERT #ifdef SPCPPL_DEBUG #define SPCPPL_ASSERT(condition) \ if(!(condition)) { \ throw std::runtime_error(std::string() + #condition + " in line " + std::to_string(__LINE__) + " in " + __PRETTY_FUNCTION__); \ } #else #define SPCPPL_ASSERT(condition) #endif #endif /** * Support decrementing and multi-passing, but not declared bidirectional(or even forward) because * it's reference type is not a reference. * * It doesn't return reference because * 1. Anyway it'll not satisfy requirement [forward.iterators]/6 * If a and b are both dereferenceable, then a == b if and only if *a and * b are bound to the same object. * 2. It'll not work with reverse_iterator that returns operator * of temporary which is temporary for this iterator * * Note, reverse_iterator is not guaranteed to work now too since it works only with bidirectional iterators, * but it's seems to work at least on my implementation. * * It's not really useful anywhere except iterating anyway. */ template <typename T> class IntegerIterator: public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> { public: explicit IntegerIterator(T value): value(value) { } IntegerIterator& operator++() { ++value; return *this; } IntegerIterator operator++(int) { IntegerIterator copy = *this; ++value; return copy; } IntegerIterator& operator--() { --value; return *this; } IntegerIterator operator--(int) { IntegerIterator copy = *this; --value; return copy; } T operator*() const { return value; } bool operator==(IntegerIterator rhs) { return value == rhs.value; } bool operator!=(IntegerIterator rhs) { return !(*this == rhs); } private: T value; }; template <typename T> class IntegerRange { public: IntegerRange(T begin, T end): begin_(begin), end_(end) { SPCPPL_ASSERT(begin <= end); } IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); } IntegerIterator<T> end() const { return IntegerIterator<T>(end_); } private: T begin_; T end_; }; template <typename T> class ReversedIntegerRange { typedef std::reverse_iterator<IntegerIterator<T>> IteratorType; public: ReversedIntegerRange(T begin, T end): begin_(begin), end_(end) { SPCPPL_ASSERT(begin >= end); } IteratorType begin() const { return IteratorType(IntegerIterator<T>(begin_)); } IteratorType end() const { return IteratorType(IntegerIterator<T>(end_)); } private: T begin_; T end_; }; template <typename T> IntegerRange<T> range(T to) { return IntegerRange<T>(0, to); } template <typename T> IntegerRange<T> range(T from, T to) { return IntegerRange<T>(from, to); } template <typename T> IntegerRange<T> inclusiveRange(T to) { return IntegerRange<T>(0, to + 1); } template <typename T> IntegerRange<T> inclusiveRange(T from, T to) { return IntegerRange<T>(from, to + 1); } template <typename T> ReversedIntegerRange<T> downrange(T from) { return ReversedIntegerRange<T>(from, 0); } template <typename T> ReversedIntegerRange<T> downrange(T from, T to) { return ReversedIntegerRange<T>(from, to); } template <typename T> ReversedIntegerRange<T> inclusiveDownrange(T from) { return ReversedIntegerRange<T>(from + 1, 0); } template <typename T> ReversedIntegerRange<T> inclusiveDownrange(T from, T to) { return ReversedIntegerRange<T>(from + 1, to); } using namespace std; class D { public: void solve(std::istream& in, std::ostream& out) { int n, k; in >> n >> k; vector<int> used(n); int ans = 0; vector<int> v(n); for (int i: range(n)) { in >> v[i]; --v[i]; } if (v[0] != 0) { ++ans; } v[0] = 0; used[0] = true; vector<int> dp(n); function<int(int)> get = [&](int x) { if (used[x]) return dp[x]; used[x] = true; return dp[x] = get(v[x]) + 1; }; for (int i: range(1, n)) { get(i); if (dp[i] % k == 1 % k && dp[i] > 1) { ++ans; } } cerr << endl; out << ans; } }; int main() { std::ios_base::sync_with_stdio(false); D solver; std::istream& in(std::cin); std::ostream& out(std::cout); in.tie(0); out << std::fixed; out.precision(20); solver.solve(in, out); return 0; }
a.cc:48:36: warning: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> struct std::iterator' is deprecated [-Wdeprecated-declarations] 48 | class IntegerIterator: public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> { | ^~~~~~~~ In file included from /usr/include/c++/14/bits/stl_iterator_base_funcs.h:66, 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:7: /usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: declared here 127 | struct _GLIBCXX17_DEPRECATED iterator | ^~~~~~~~ a.cc: In member function 'void D::solve(std::istream&, std::ostream&)': a.cc:198:17: error: 'function' was not declared in this scope 198 | function<int(int)> get = [&](int x) { | ^~~~~~~~ a.cc:15:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>' 14 | #include <iterator> +++ |+#include <functional> 15 | a.cc:198:26: error: expected primary-expression before 'int' 198 | function<int(int)> get = [&](int x) { | ^~~ a.cc:207:28: error: no matching function for call to 'get(int&)' 207 | get(i); | ~~~^~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/string:51: /usr/include/c++/14/bits/stl_pair.h:1250:5: note: candidate: '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 | ^~~ /usr/include/c++/14/bits/stl_pair.h:1250:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::pair<_Tp1, _Tp2>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1255:5: note: candidate: '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:1255:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::pair<_Tp1, _Tp2>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1260:5: note: candidate: '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:1260:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::pair<_Tp1, _Tp2>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1265:5: note: candidate: '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:1265:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::pair<_Tp1, _Tp2>' and 'int' 207 | get(i); | ~~~^~~ In file included from /usr/include/c++/14/bits/memory_resource.h:47, from /usr/include/c++/14/string:68: /usr/include/c++/14/tuple:2445:5: note: candidate: '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/tuple:2445:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::tuple<_Elements ...>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/tuple:2451:5: note: candidate: '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:2451:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::tuple<_Elements ...>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/tuple:2457:5: note: candidate: '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:2457:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::tuple<_Elements ...>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/tuple:2466:5: note: candidate: '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:2466:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::tuple<_Elements ...>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:138:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(array<_Tp, _Nm>&)' 138 | get(array<_Tp, _Nm>&) noexcept; | ^~~ /usr/include/c++/14/bits/stl_pair.h:138:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::array<_Tp, _Nm>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:142:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(array<_Tp, _Nm>&&)' 142 | get(array<_Tp, _Nm>&&) noexcept; | ^~~ /usr/include/c++/14/bits/stl_pair.h:142:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::array<_Tp, _Nm>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:146:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const array<_Tp, _Nm>&)' 146 | get(const array<_Tp, _Nm>&) noexcept; | ^~~ /usr/include/c++/14/bits/stl_pair.h:146:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::array<_Tp, _Nm>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:150:5: note: candidate: 'template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp&& std::get(const array<_Tp, _Nm>&&)' 150 | get(const array<_Tp, _Nm>&&) noexcept; | ^~~ /usr/include/c++/14/bits/stl_pair.h:150:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::array<_Tp, _Nm>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1272:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_T1, _T2>&)' 1272 | get(pair<_Tp, _Up>& __p) noexcept | ^~~ /usr/include/c++/14/bits/stl_pair.h:1272:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::pair<_T1, _T2>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1277:5: note: candidate: '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:1277:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::pair<_T1, _T2>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1282:5: note: candidate: '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:1282:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'std::pair<_T1, _T2>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1287:5: note: candidate: '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:1287:5: note: template argument deduction/substitution failed: a.cc:207:28: note: mismatched types 'const std::pair<_T1, _T2>' and 'int' 207 | get(i); | ~~~^~~ /usr/include/c++/14/bits/stl_pair.h:1292:5: note: candidate: 'template<class _Tp, class _Up> constexpr _Tp& std::get(pair<_Up, _Tp>&)' 1292 | get(pair<_Up, _Tp
s597533425
p04008
C++
#include <map> #include <set> #include <cmath> #include <ctime> #include <cstdio> #include <vector> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; #define mp make_pair #define pb push_back #define x first #define y second typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; const int N=100010; int ans,a[N],next[N],head[N]; int dfs(int k,int d) { int p=head[k],t=0; while (p) { t=max(t,dfs(p,d)+1); p=next[p]; } if (t==d-1&&a[k]!=1) {ans++;return -1;} return t; } int main() { #ifdef waltz freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); #endif int n,k;scanf("%d%d",&n,&k); for (int i=1;i<=n;i++) scanf("%d",&a[i]); ans=0; if (a[1]!=1) {ans++;a[1]=1;} for (int i=2;i<=n;i++) if (a[i]!=1) { next[i]=head[a[i]];head[a[i]]=i; } for (int i=2;i<=n;i++) if (a[i]==1) dfs(i,k); printf("%d\n",ans); return 0; }
a.cc: In function 'int dfs(int, int)': a.cc:33:11: error: reference to 'next' is ambiguous 33 | p=next[p]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/bits/stl_tree.h:63, from /usr/include/c++/14/map:62, 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:25:14: note: 'int next [100010]' 25 | int ans,a[N],next[N],head[N]; | ^~~~ a.cc: In function 'int main()': a.cc:52:13: error: reference to 'next' is ambiguous 52 | next[i]=head[a[i]];head[a[i]]=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:25:14: note: 'int next [100010]' 25 | int ans,a[N],next[N],head[N]; | ^~~~
s082734107
p04009
C++
#include<bits/stdc++.h> using namespace std; #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcount #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC const int N = 101; int n, m; string a[N]; short int dp[N][N][N][N]; void upd(int &a, int b) { a = max(a, b); } int pref[N][N]; int lx_, ly_, rx_, ry_; int sum(int x1, int y1, int x2, int y2) { x1 = max(x1, lx_); y1 = max(y1, ly_); x2 = min(x2, rx_); y2 = min(y2, ry_); if (x2 < x1 || y2 < y1) return 0; return pref[x2 + 1][y2 + 1] - pref[x2 + 1][y1] - pref[x1][y2 + 1] + pref[x1][y1]; } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n >> m; int Ex, Ey; for (int i = 0; i < n; ++i) { cin >> a[i]; for (int j = 0; j < m; ++j) { if (a[i][j] == 'E') { Ex = i; Ey = j; } } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { pref[i + 1][j + 1] = pref[i + 1][j] + pref[i][j + 1] - pref[i][j] + (a[i][j] == 'o'); } } int ans = 0; for (int lx = n - 1; lx >= 0; --lx) { for (int ly = m - 1; ly >= 0; --ly) { for (int rx = lx; rx < n; ++rx) { for (int ry = ly; ry < m; ++ry) { lx_ = rx - Ex; ly_ = ry - Ey; rx_ = lx + (n - 1 - Ex); ry_ = ly + (m - 1 - Ey); int cur = dp[lx][ly][rx][ry]; upd(ans, cur); if (lx) { int cnt = sum(lx - 1, ly, lx - 1, ry); upd(dp[lx - 1][ly][rx][ry], cur + cnt); } if (ly) { int cnt = sum(lx, ly - 1, rx, ly - 1); upd(dp[lx][ly - 1][rx][ry], cur + cnt); } if (rx + 1 < n) { int cnt = sum(rx + 1, ly, rx + 1, ry); upd(dp[lx][ly][rx + 1][ry], cur + cnt); } if (ry + 1 < m) { int cnt = sum(lx, ry + 1, rx, ry + 1); upd(dp[lx][ly][rx][ry + 1], cur + cnt); } } } } } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:75:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int' 75 | upd(dp[lx - 1][ly][rx][ry], cur + cnt); | ~~~~~~~~~~~~~~~~~~~~~^ a.cc:16:15: note: initializing argument 1 of 'void upd(int&, int)' 16 | void upd(int &a, int b) { | ~~~~~^ a.cc:79:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int' 79 | upd(dp[lx][ly - 1][rx][ry], cur + cnt); | ~~~~~~~~~~~~~~~~~~~~~^ a.cc:16:15: note: initializing argument 1 of 'void upd(int&, int)' 16 | void upd(int &a, int b) { | ~~~~~^ a.cc:83:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int' 83 | upd(dp[lx][ly][rx + 1][ry], cur + cnt); | ~~~~~~~~~~~~~~~~~~~~~^ a.cc:16:15: note: initializing argument 1 of 'void upd(int&, int)' 16 | void upd(int &a, int b) { | ~~~~~^ a.cc:87:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int' 87 | upd(dp[lx][ly][rx][ry + 1], cur + cnt); | ~~~~~~~~~~~~~~~~~~~~~^ a.cc:16:15: note: initializing argument 1 of 'void upd(int&, int)' 16 | void upd(int &a, int b) { | ~~~~~^
s532141423
p04009
C++
#include<iostream> #include<cstdio> #include<algorithm> #include<cassert> #include<cmath> #include<vector> #include<map> #include<set> #include<string> #include<queue> #include<stack> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF ((1<<30)-1) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; int field[110][110]; int h, w, ex, ey; char c; short dp[101][101][101][101]; int cnt(int il, int ir, int jl, int jr){ if(il > ir || jl > jr)return 0; il--,jl--; return field[ir][jr] + field[il][jl] - field[ir][jl] - field[il][jr]; } int cnti(int il, int ir, int jl, int jr, int i){ int ill = i, irr = i, jll = jl, jrr= jr; ill = max(ill, ir - ex + 1); irr = min(irr, il + h -ex); jll = max(jll, jr - ey + 1); jrr = min(jrr, jl + w - ey); return cnt(ill, irr, jll, jrr); } int cntj(int il, int ir, int jl, int jr, int j){ int ill = il, irr = ir, jll = j, jrr= j; ill = max(ill, ir - ex + 1); irr = min(irr, il + h -ex); jll = max(jll, jr - ey + 1); jrr = min(jrr, jl + w - ey); return cnt(ill, irr, jll, jrr); } int main(){ cin >> h >> w; for(int i = 1;i <= h;i++){ for(int j = 1;j <= w;j++){ cin >> c; if(c == 'o')field[i][j] = 1; if(c == 'E')ex = i, ey = j; field[i][j] -= field[i-1][j-1] - field[i-1][j] - field[i][j-1]; } } for(int iwidth = 0;iwidth <= h;iwidth++){ for(int jwidth = 0;jwidth <= w;jwidth++){ for(int il = 1;il+iwidth <= h;il++){ int ir = il + iwidth; for(int jl = 1;jl + jwidth <= w;jl++){ int jr = jl + jwidth; int tmp = dp[il][ir][jl][jr]; dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1)); dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+1)); dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-1)); dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+1)); } } } } cout << dp[1][h][1][w] << endl; return 0; }
a.cc: In function 'int main()': a.cc:68:47: error: no matching function for call to 'max(short int&, int)' 68 | dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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:68:47: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') 68 | dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /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, from a.cc:3: /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:68:47: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' 68 | dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:69:47: error: no matching function for call to 'max(short int&, int)' 69 | dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+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:69:47: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') 69 | dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /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:69:47: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' 69 | dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:70:47: error: no matching function for call to 'max(short int&, int)' 70 | dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-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:70:47: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') 70 | dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /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:70:47: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' 70 | dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:71:47: error: no matching function for call to 'max(short int&, int)' 71 | dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+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:71:47: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') 71 | dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /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:71:47: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' 71 | dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+1)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s371078858
p04009
C
#include <bits/stdc++.h> using std::max; char s[105]; int a[205][205],dp[105][105][105][105],ans,h,w,sx,sy; int sh[105][105],sl[105][105]; #define ch(x,l,r) sh[x][r]-sh[x][l-1] #define cl(x,l,r) sl[x][r]-sl[x][l-1] #define m(x,y) x=max(x,y) int main(){ scanf("%d%d",&h,&w); for (int i=1;i<=h;i++) { scanf("%s",s+1); for (int j=1;j<=w;j++){ if (s[j]=='o') a[i][j]=1; if (s[j]=='E') sx=i,sy=j; } } for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) sh[i][j]=a[i][j]+sh[i][j-1],sl[j][i]=a[i][j]+sl[j][i-1]; for (int i=0;i<=h+1;i++) for (int j=0;j<=w+1;j++) for (int i2=0;i2<=h+1;i2++) for (int j2=0;j2<=w+1;j2++) dp[i][j][i2][j2]=-1; dp[sx][sy][sx][sy]=0; for (int i=sx;i>=1;i--) for (int j=sy;j>=1;j--) for (int i2=sx;i2<=h;i2++) for (int j2=sy;j2<=w;j2++){ if (i==sx && i2==sx && j==sy && j2==sy) continue; if (dp[i+1][j][i2][j2]>=0 && i>i2-sx && i!=sx) m(dp[i][j][i2][j2],dp[i+1][j][i2][j2]+ch(i,j,j2)); if (dp[i][j][i2-1][j2]>=0 && i2<=h-(sx-i) && i2!=sx) m(dp[i][j][i2][j2],dp[i][j][i2-1][j2]+ch(i2,j,j2)); if (dp[i][j+1][i2][j2]>=0 && j>j2-sy && j!=sy) m(dp[i][j][i2][j2],dp[i][j+1][i2][j2]+cl(j,i,i2)); if (dp[i][j][i2][j2-1]>=0 && j2<=w-(sy-j) && j2!=sy) m(dp[i][j][i2][j2],dp[i][j][i2][j2-1]+cl(j2,i,i2)); ans=max(ans,dp[i][j][i2][j2]); } printf("%d\n",ans); }
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory 1 | #include <bits/stdc++.h> | ^~~~~~~~~~~~~~~ compilation terminated.
s942624095
p04009
C++
#include<cstdio> #include<iostream> #include<cstring> #define RG register using namespace std; const int N=101; short n,m,x,y,ans,dp[N][N][N][N],sum[N][N]; char g[N][N]; template<typename I> inline void read(I &ot){ I ch=getchar(), x=0, f=1; while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar(); } ot=x*f;} template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);} template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;} template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;} template<typename I>inline void swp(I&a,I&b){I t=a; a=b; b=t;} inline short s(short a,short b,short c,short d){ if(a>c) swp(a,c); if(b>d) swp(b,d); return sum[c][d]-sum[c][b-1]-sum[a-1][d]+sum[a-1][b-1]; } int main() { // freopen("Salvage Robots.in","r",stdin); //freopen(".out","w",stdout); read(n,m); for(short i=1;i<=n;i++) { scanf("%s",g[i]+1); for(short j=1;j<=m;j++) { if(g[i][j]=='o') sum[i][j]=1; else if(g[i][j]=='E') x=i, y=j; sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]; } } for(short i=x;i;i--) for(short j=y;j;j--) for(short k=x;k<=n;k++) for(short l=y;l<=m;l++) { ans=mx(ans,dp[i][j][k][l]); // short ri=m-l+y, li=y-j+1, us=x-i+1, ds=n-k+x; short li=l-y+1, ri=m-y+j, us=k-x+1, ds=n-x+i; if(i-1>=us) dp[i-1][j][k][l]=mx(dp[i-1][j][k][l],dp[i][j][k][l]+s(i-1,mx(li,j),i-1,mi(ri,l))); if(j-1>=li) dp[i][j-1][k][l]=mx(dp[i][j-1][k][l],dp[i][j][k][l]+s(mx(i,us),j-1,mi(k,ds),j-1)); if(k+1<=ds) dp[i][j][k+1][l]=mx(dp[i][j][k+1][l],dp[i][j][k][l]+s(k+1,mx(li,j),k+1,mi(ri,l))); if(l+1<=ri) dp[i][j][k][l+1]=mx(dp[i][j][k][l+1],dp[i][j][k][l]+s(mx(i,us),l+1,mi(k,ds),l+1)); } // printf("%d\n",ans); cout<<ans<<endl; //fclose(stdin); fclose(stdout); return 0; }
a.cc: In function 'int main()': a.cc:45:56: error: no matching function for call to 'mx(short int&, int)' 45 | if(i-1>=us) dp[i-1][j][k][l]=mx(dp[i-1][j][k][l],dp[i][j][k][l]+s(i-1,mx(li,j),i-1,mi(ri,l))); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:15:30: note: candidate: 'template<class I> I mx(const I&, const I&)' 15 | template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;} | ^~ a.cc:15:30: note: template argument deduction/substitution failed: a.cc:45:56: note: deduced conflicting types for parameter 'const I' ('short int' and 'int') 45 | if(i-1>=us) dp[i-1][j][k][l]=mx(dp[i-1][j][k][l],dp[i][j][k][l]+s(i-1,mx(li,j),i-1,mi(ri,l))); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:46:56: error: no matching function for call to 'mx(short int&, int)' 46 | if(j-1>=li) dp[i][j-1][k][l]=mx(dp[i][j-1][k][l],dp[i][j][k][l]+s(mx(i,us),j-1,mi(k,ds),j-1)); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:15:30: note: candidate: 'template<class I> I mx(const I&, const I&)' 15 | template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;} | ^~ a.cc:15:30: note: template argument deduction/substitution failed: a.cc:46:56: note: deduced conflicting types for parameter 'const I' ('short int' and 'int') 46 | if(j-1>=li) dp[i][j-1][k][l]=mx(dp[i][j-1][k][l],dp[i][j][k][l]+s(mx(i,us),j-1,mi(k,ds),j-1)); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:47:56: error: no matching function for call to 'mx(short int&, int)' 47 | if(k+1<=ds) dp[i][j][k+1][l]=mx(dp[i][j][k+1][l],dp[i][j][k][l]+s(k+1,mx(li,j),k+1,mi(ri,l))); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:15:30: note: candidate: 'template<class I> I mx(const I&, const I&)' 15 | template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;} | ^~ a.cc:15:30: note: template argument deduction/substitution failed: a.cc:47:56: note: deduced conflicting types for parameter 'const I' ('short int' and 'int') 47 | if(k+1<=ds) dp[i][j][k+1][l]=mx(dp[i][j][k+1][l],dp[i][j][k][l]+s(k+1,mx(li,j),k+1,mi(ri,l))); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:48:56: error: no matching function for call to 'mx(short int&, int)' 48 | if(l+1<=ri) dp[i][j][k][l+1]=mx(dp[i][j][k][l+1],dp[i][j][k][l]+s(mx(i,us),l+1,mi(k,ds),l+1)); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:15:30: note: candidate: 'template<class I> I mx(const I&, const I&)' 15 | template<typename I>inline I mx(const I&a,const I&b){return a>b ? a : b;} | ^~ a.cc:15:30: note: template argument deduction/substitution failed: a.cc:48:56: note: deduced conflicting types for parameter 'const I' ('short int' and 'int') 48 | if(l+1<=ri) dp[i][j][k][l+1]=mx(dp[i][j][k][l+1],dp[i][j][k][l]+s(mx(i,us),l+1,mi(k,ds),l+1)); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s413990945
p04009
C++
#include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> using namespace std; short line[103][103],list[103][103],f[103][103][103][103],n,m,op,sx,sy; char s[103][103]; inline short min(short a,short b){ if(a<b) return a; return b; } inline short max(short a,short b){ if(a>b) return a; return b; } int main(){ cin>>n>>m; for(short i=1;i<=n;i++){ cin>>(s[i]+1); } for(short i=1;i<=n;i++){ for(short j=1;j<=m;j++){ line[i][j]=line[i][j-1]+(s[i][j]=='o'); list[i][j]=list[i-1][j]+(s[i][j]=='o'); if(s[i][j]=='E'){ sx=i,sy=j; } } } for(short i=sx;i;i--){ for(short j=sy;j;j--){ for(short k=sx;k<=n;k++){ for(short p=sy;p<=m;p++){ if(1<i&&k+1<sx+i){ f[i-1][j][k][p]=max(f[i-1][j][k][p],f[i][j][k][p]+line[i-1][min(p,m-sy+j)]-line[i-1][max(j-1,p-sy)]); op=max(op,ans[i-1][j][k][p]); } if(k<n&&sx+k<n+i){ f[i][j][k+1][p]=max(f[i][j][k+1][p],f[i][j][k][p]+line[k+1][min(p,m-sy+j)]-line[k+1][max(j-1,p-sy)]); op=max(op,ans[i][j][k+1][p]); } if(1<j&&p+1<sy+j){ f[i][j-1][k][p]=max(f[i][j-1][k][p],f[i][j][k][p]+list[min(k,n-sx+i)][j-1]-list[max(i-1,k-sx)][j-1]); op=max(op,ans[i][j-1][k][p]); } if(p<m&&sy+p<m+j){ f[i][j][k][p+1]=max(f[i][j][k][p+1],f[i][j][k][p]+list[min(k,n-sx+i)][p+1]-list[max(i-1,k-sx)][p+1]); op=max(op,ans[i][j][k][p+1]); } } } } } cout<<op<<endl; return 0; }
a.cc: In function 'int main()': a.cc:36:59: error: 'ans' was not declared in this scope; did you mean 'abs'? 36 | op=max(op,ans[i-1][j][k][p]); | ^~~ | abs a.cc:40:59: error: 'ans' was not declared in this scope; did you mean 'abs'? 40 | op=max(op,ans[i][j][k+1][p]); | ^~~ | abs a.cc:44:59: error: 'ans' was not declared in this scope; did you mean 'abs'? 44 | op=max(op,ans[i][j-1][k][p]); | ^~~ | abs a.cc:48:59: error: 'ans' was not declared in this scope; did you mean 'abs'? 48 | op=max(op,ans[i][j][k][p+1]); | ^~~ | abs
s182108003
p04009
C++
#include <bits/stdc++.h> #define y1 __zzd001 using namespace std; const int N=105; int n,m,ax,ay,bx,by; char s[N][N]; short g[N][N],dp[N][N][N][N]; short Get(int x1,int y1,int x2,int y2){ return g[x2][y2]-g[x2][y1-1]-g[x1-1][y2]+g[x1-1][y1-1]; } short max(short a,short b){ return a>b?a:b; } short DP(int x1,int y1,int x2,int y2){ // printf("DP %d %d %d %d\n",(int)x1,(int)y1,(int)x2,(int)y2); short &v=dp[x1][y1][x2][y2]; if (~v) return v; if (x1>x2||y1>y2) return v=0; short xL=max(x2-bx+1,x1),xR=min(x1+ax-1,x2); short yL=max(y2-by+1,y1),yR=min(y1+ay-1,y2); return v=max( max(DP(x1,y1,x2,y2-1)+((yR==y2)?Get(xL,y2,xR,y2):0), DP(x1,y1+1,x2,y2)+((yL==y1)?Get(xL,y1,xR,y1):0), max(DP(x1,y1,x2-1,y2)+((xR==x2)?Get(x2,yL,x2,yR):0), DP(x1+1,y1,x2,y2)+((xL==x1)?Get(x1,yL,x1,yR):0))); } int main(){ memset(g,0,sizeof g); scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%s",s[i]+1); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (s[i][j]=='o') g[i][j]++; else if (s[i][j]=='E') ax=i,bx=n-i+1,ay=j,by=m-j+1; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) g[i][j]=g[i][j]+g[i][j-1]+g[i-1][j]-g[i-1][j-1]; memset(dp,-1,sizeof dp); printf("%d",(int)DP(1,1,n,m)); return 0; }
a.cc: In function 'short int DP(int, int, int, int)': a.cc:27:82: error: expected ')' before ';' token 27 | DP(x1+1,y1,x2,y2)+((xL==x1)?Get(x1,yL,x1,yR):0))); | ^ | ) a.cc:23:21: note: to match this '(' 23 | return v=max( | ^ 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: In instantiation of 'constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]': a.cc:24:7: required from here 24 | max(DP(x1,y1,x2,y2-1)+((yR==y2)?Get(xL,y2,xR,y2):0), | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 25 | DP(x1,y1+1,x2,y2)+((yL==y1)?Get(xL,y1,xR,y1):0), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26 | max(DP(x1,y1,x2-1,y2)+((xR==x2)?Get(x2,yL,x2,yR):0), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27 | DP(x1+1,y1,x2,y2)+((xL==x1)?Get(x1,yL,x1,yR):0))); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:306:17: error: '__comp' cannot be used as a function 306 | if (__comp(__a, __b)) | ~~~~~~^~~~~~~~~~
s689751534
p04009
C++
#include<bits/stdc++.h> #define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++) using namespace std; const int N=105; char mp[N][N]; int n,m,ex,ey,ans; int sr[N][N],sc[N][N]; int dp[N][N][N]; void mx(int &x,int y){ x<y?x=y:0; } int main(){ scanf("%d%d",&n,&m); CLR(dp,-1); For(i,1,n) scanf("%s",mp[i]+1); For(i,1,n) For(j,1,m) if (mp[i][j]=='o') sr[i][j]=sc[i][j]=1; else if (mp[i][j]=='E') ex=i,ey=j; For(i,1,n) For(j,1,m) sr[i][j]+=sr[i][j-1], sc[i][j]+=sc[i-1][j]; int L=ey-1,R=m-ey,U=ex-1,D=n-ex; dp[0][0][0]=0; For(l,0,L) For(r,0,R) For(u,0,U) For(d,0,D){ if (dp[r][u][d]==-1) continue; ans=max(ans,dp[r][u][d]); int up=max(ex-u,d+1),dn=min(ex+d,n-u); int le=max(ey-l,r+1),ri=min(ey+r,m-l); if (up>dn||le>ri) continue; if (u<U-d) mx(dp[r][u+1][d],dp[r][u][d]+sr[ex-u-1][ri]-sr[ex-u-1][le-1]); if (d<D-u) mx(dp[r][u][d+1],dp[r][u][d]+sr[ex+d+1][ri]-sr[ex+d+1][le-1]); if (r<R-l) mx(dp[r+1][u][d],dp[r][u][d]+sc[dn][ey+r+1]-sc[up-1][ey+r+1]); if (l<L-r) mx(dp[r][u][d] ,dp[r][u][d]+sc[dn][ey-l-1]-sc[up-1][ey-l-1]); } printf("%d",ans); }
a.cc: In function 'int main()': a.cc:13:30: error: 'CLR' was not declared in this scope 13 | scanf("%d%d",&n,&m); CLR(dp,-1); | ^~~
s350091572
p04009
C++
/*+lmake * STD = c++14 * DEFINE += WAAUTOMATON */ #include <bits/stdc++.h> using namespace std; using LL=long long; using ULL=unsigned long long; #ifdef WAAUTOMATON #define debug(args...) \ { \ dbg, args; \ cerr << endl; \ } #define massert(x) assert(x) #else #define debug(args...) // Just strip off all debug tokens #define massert(x) #endif struct debugger { template<typename T> debugger& operator , (const T& v) { cerr<<v<<" "; return *this; } } dbg; #define MAXN 100 short a[MAXN+10][MAXN+10],s[MAXN+10][MAXN+10]; int h,w; int query(int x1,int y1,int x2,int y2) { if (x1>x2 || y1>y2 || x1<0 || y1<0 || x2>h || y2>w) return -10000; return sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1]; } short f[MAXN+5][MAXN+5][MAXN+5][MAXN+5]; int main(){ #ifdef WAAUTOMATON //freopen("in.txt","r",stdin); #endif cin>>h>>w; int sx,sy; for(int i=1; i<=h; ++i) { for(int j=1; j<=w; ++j) { char t; cin>>t; if (t=='E') { sx=i; sy=j; } else (t=='o') { a[i][j]=1; } } } for(int i=1; i<=h; ++i) { for(int j=1; j<=w; ++j) { sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j]; } } for(int l=0; l<w; ++l) { for(int u=0; u<h; ++u) { for(int r=0; r<w-l; ++r) { for(int d=0; d<h-u; ++d) { f[l+1][u][r][d]=max(f[l+1][u][r][d], f[l][u][r][d]+query(max(sx-u,d),sy-(l+1),min(sx+d,h-u),sy-(l+1)); f[l][u+1][r][d]=max(f[l][u+1][r][d], f[l][u][r][d]+query(max(sx-u,d),sy-(l+1),min(sx+d,h-u),sy-(l+1)); } } } } return 0; }
a.cc: In function 'int query(int, int, int, int)': a.cc:34:16: error: 'sum' was not declared in this scope 34 | return sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1]; | ^~~ a.cc: In function 'int main()': a.cc:50:40: error: expected ';' before '{' token 50 | } else (t=='o') { | ^~ | ; a.cc:57:25: error: 'sum' was not declared in this scope 57 | sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j]; | ^~~ a.cc:65:113: error: expected ')' before ';' token 65 | f[l][u][r][d]+query(max(sx-u,d),sy-(l+1),min(sx+d,h-u),sy-(l+1)); | ^ | ) a.cc:64:60: note: to match this '(' 64 | f[l+1][u][r][d]=max(f[l+1][u][r][d], | ^ a.cc:67:113: error: expected ')' before ';' token 67 | f[l][u][r][d]+query(max(sx-u,d),sy-(l+1),min(sx+d,h-u),sy-(l+1)); | ^ | ) a.cc:66:60: note: to match this '(' 66 | f[l][u+1][r][d]=max(f[l][u+1][r][d], | ^
s752101114
p04009
C++
#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> using namespace std; #define re return #define in inline #define inc(l, i, r) for(i=l; i<r; ++i) const short mxn=1<<7; short h, w, xe, ye, a[mxn][mxn], s[mxn][mxn], f[mxn][mxn][mxn][mxn]; char str[mxn]; in void upd(short& a, short b){a<b? a=b: 0;} in short sum(short x1, short x2, short y1, short y2) {re s[x2][y2]+s[x1-1][y1-1]-s[x2][y1-1]-s[x1-1][y2];} short main() { short i, j, k, l, ans=0; scanf("%d%d\n", &h, &w); inc(1, i, h+1) { scanf("%s", str); // gets(str); inc(1, j, w+1) switch(str[j-1]) { case 'o': a[i][j]=1; break; case 'E': xe=i, ye=j; } } inc(1, i, h+1) inc(1, j, w+1) s[i][j]=a[i][j]-s[i-1][j-1]+s[i][j-1]+s[i-1][j]; inc(0, i, xe+1) inc(0, j, ye+1) inc(0, k, h-xe+1) inc(0, l, w-ye+1) { // printf("%d %d %d %d : %d\n", i, j, k, l, f[i][j][k][l]); upd(ans, f[i][j][k][l]); if(i+k+1<xe) upd( f[i+1][j][k][l], f[i][j][k][l]+ sum( xe-i-1, xe-i-1, max(ye-j, l+1), min(ye+l, w-j) ) ); if(xe+i+k<h) upd( f[i][j][k+1][l], f[i][j][k][l]+ sum( xe+k+1, xe+k+1, max(ye-j, l+1), min(ye+l, w-j) ) ); if(j+l+1<ye) upd( f[i][j+1][k][l], f[i][j][k][l]+ sum( max(xe-i, k+1), min(xe+k, h-i), ye-j-1, ye-j-1 ) ); if(ye+j+l<w) upd( f[i][j][k][l+1], f[i][j][k][l]+ sum( max(xe-i, k+1), min(xe+k, h-i), ye+l+1, ye+l+1 ) ); } printf("%d\n", ans); re 0; }
cc1plus: error: '::main' must return 'int'
s188096505
p04009
C++
#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> using namespace std; #define re return #define in inline #define inc(l, i, r) for(i=l; i<r; ++i) const int mxn=1<<7; int h, w, xe, ye, a[mxn][mxn], s[mxn][mxn], f[mxn][mxn][mxn][mxn]; char str[mxn]; in void upd(int& a, int b){a<b? a=b: 0;} in int sum(int x1, int x2, int y1, int y2) {re s[x2][y2]+s[x1-1][y1-1]-s[x2][y1-1]-s[x1-1][y2];} int main() { int i, j, k, l, ans=0; scanf("%d%d\n", &h, &w); inc(1, i, h+1) { gets(str); inc(1, j, w+1) switch(str[j-1]) { case 'o': a[i][j]=1; break; case 'E': xe=i, ye=j; } } inc(1, i, h+1) inc(1, j, w+1) s[i][j]=a[i][j]-s[i-1][j-1]+s[i][j-1]+s[i-1][j]; inc(0, i, xe+1) inc(0, j, ye+1) inc(0, k, h-xe+1) inc(0, l, w-ye+1) { // printf("%d %d %d %d : %d\n", i, j, k, l, f[i][j][k][l]); upd(ans, f[i][j][k][l]); if(i+k+1<xe) upd( f[i+1][j][k][l], f[i][j][k][l]+ sum( xe-i-1, xe-i-1, max(ye-j, l+1), min(ye+l, w-j) ) ); if(xe+i+k<h) upd( f[i][j][k+1][l], f[i][j][k][l]+ sum( xe+k+1, xe+k+1, max(ye-j, l+1), min(ye+l, w-j) ) ); if(j+l+1<ye) upd( f[i][j+1][k][l], f[i][j][k][l]+ sum( max(xe-i, k+1), min(xe+k, h-i), ye-j-1, ye-j-1 ) ); if(ye+j+l<w) upd( f[i][j][k][l+1], f[i][j][k][l]+ sum( max(xe-i, k+1), min(xe+k, h-i), ye+l+1, ye+l+1 ) ); } printf("%d\n", ans); re 0; }
a.cc: In function 'int main()': a.cc:26:9: error: 'gets' was not declared in this scope; did you mean 'getw'? 26 | gets(str); | ^~~~ | getw
s381940955
p04009
C++
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define forE(i,x) for(int i=head[x];i!=-1;i=ne[i]) typedef long long i64; typedef unsigned long long u64; typedef unsigned u32; typedef pair<int,int> pin; #define mk(a,b) make_pair(a,b) #define lowbit(x) ((x)&(-(x))) #define sqr(a) ((a)*(a)) #define clr(a) (memset((a),0,sizeof(a))) #define ls ((x)<<1) #define rs (((x)<<1)|1) #define mid (((l)+(r))>>1) #define pb push_back #define w1 first #define w2 second inline void read(int &x){ x=0;int 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();} x*=f; } inline void judge(){ freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); } /******************************head*******************************/ using namespace std; int n, m, ex, ey; const int N(105); short sumr[N][N], sumc[N][N]; char st[N][N], b[N][N]; short dp[N][N][N][N]; int main() { read(n);read(m); for(int i(0); i < n; i++) { scanf("%s", st[i]); for(int j(0); j < m; j++) { if(st[i][j] == 'E') { ex = i; ey = j; } } } int ans(0); for(int i(0); i < n; i++) { for(int j(0); j < m; j++) { sumr[i][j] = j == 0 ? st[i][j] == 'o' : sumr[i][j - 1] + (st[i][j] == 'o'); sumc[i][j] = i == 0 ? st[i][j] == 'o' : sumc[i - 1][j] + (st[i][j] == 'o'); } } dp[0][0][0][0] = 0; for(int l(0); l <= m; l++) { for(int r(0); r + l <= m; r++) { for(int u(0); u <= n; u++) { for(int d(0); u + d <= n; d++) { if(l + r < m) { int a(max(d, ex - u)), b(min(n - 1 - u, ex + d)); short delta(ey + r + 1 <= m - 1 - l ? sumc[b][ey + r + 1] - (a == 0 ? 0 : sumc[a - 1][ey + r + 1]) : 0); dp[l][r + 1][u][d] = max((int)dp[l][r + 1][u][d], dp[l][r][u][d] + delta); delta = ey - l - 1 >= r ? sumc[b][ey - l - 1] - (a == 0 ? 0 : sumc[a - 1][ey - l - 1]) : 0; dp[l + 1][r][u][d] = max((int)dp[l + 1][r][u][d], dp[l][r][u][d] + delta); } if(u + d < n) { int a(max(r, ey - l)), b(min(m - 1 - l, ey + r)); short delta(ex + d + 1 <= n - 1 - u ? sumr[ex + d + 1][b] - (a == 0 ? 0 : sumr[ex + d + 1][a - 1]) : 0); dp[l][r][u][d + 1] = max((int)dp[l][r][u][d + 1], dp[l][r][u][d] + delta); delta = ex - u - 1 >= d ? sumr[ex - u - 1][b] - (a == 0 ? 0 : sumr[ex - u - 1][a - 1]) : 0; dp[l][r][u + 1][d] = max((int)dp[l][r][u + 1][d], dp[l][r][u][d] + delta); } } } } } for(int l(0); l <= m; l++) { for(int u(0); u <= n; u++) { ans = max(ans, (int)dp[l][m - l][u][n - u]); } } cout << ans << endl; }
a.cc:8:9: error: 'pair' does not name a type 8 | typedef pair<int,int> pin; | ^~~~
s270028567
p04009
C++
Expand Copy #include<bits/stdc++.h> #define N 105 using namespace std; int n,m,x,y,f[N][N][N],g[N][N][N],r[N][N],c[N][N]; char st[N]; void maxself(int &x,int y){ x=max(x,y);} int main() { int i,j,k,l; scanf("%d %d\n",&n,&m); for(i=1;i<=n;i++){ scanf("%s",st+1); for(j=1;j<=m;j++){ c[j][i]=c[j][i-1],r[i][j]=r[i][j-1]; if(st[j]=='E') x=i,y=j; if(st[j]=='o') r[i][j]++,c[j][i]++; } } for(i=0;i<x;i++){ memcpy(g,f,sizeof(g)); memset(f,0,sizeof(f)); for(j=0;j<=n-x;j++) for(k=0;k<y;k++) for(l=0;l<=m-y;l++){ maxself(f[j][k][l],g[j][k][l]+(x-i-1>j ? r[x-i-1][min(y+l,m-k)]-r[x-i-1][max(y-k-1,l)] : 0)); maxself(g[j+1][k][l],g[j][k][l]+(x+j+1<=n-i ? r[x+j+1][min(y+l,m-k)]-r[x+j+1][max(y-k-1,l)] : 0)); maxself(g[j][k+1][l],g[j][k][l]+(y-k-1>l ? c[y-k-1][min(x+j,n-i)]-c[y-k-1][max(x-i-1,j)] : 0)); maxself(g[j][k][l+1],g[j][k][l]+(y+l+1<=m-k ? c[y+l+1][min(x+j,n-i)]-c[y+l+1][max(x-i-1,j)] : 0)); } } cout<<g[n-x][y-1][m-y]; return 0; }
a.cc:1:1: error: 'Expand' does not name a type 1 | Expand | ^~~~~~ 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:4: /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
s916252735
p04009
C++
/*{{{*/ #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cstring> #include <unordered_map> #include <unordered_set> #include <cassert> using namespace std; typedef pair<int, int> PP; typedef long long LL; #define pb push_back #define fr first #define sc second #define bitcnt __builtin_popcount #define all(x) x.begin(), x.end() inline int ri() {int x; scanf("%d", &x); return x;} #define rep2(i, n, ...) for (int i = 0; i < (n); i ++) #define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++) #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --) #define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --) #define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__) template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} /*}}}*/ string s[200]; const int maxn = 205; int p[maxn][maxn]; int main() { #ifdef _TEST_ freopen("input.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif int n, m; cin >> n >> m; rep(i, n) cin >> s[i]; rep(i, n) rep(j, m) p[i + 1][j + 1] = p[i][j + 1] + p[i + 1][j] + (s[i][j] == 'o') - p[i][j]; rep(i, n, maxn) rep(j, m, maxn) p[i + 1][j + 1] = p[i][j + 1] + p[i + 1][j] - p[i][j]; int dx, dy; rep(i, n) rep(j, m) if (s[i][j] == 'E') { dx = i; dy = j; } int lx = min(dx + 1, n - dx), rx = max(dx + 1, n - dx); int ly = min(dy + 1, m - dy), ry = max(dy + 1, m - dy); int res = 0; rep(i, n) rep(j, m) { smax(res, p[i + lx][j + ry] - p[i + lx][j] - p[i][j + ry] + p[i][j]); smax(res, p[i + rx][j + ly] - p[i + rx][j] - p[i][j + ly] + p[i][j]); smax(res, p[i + rx][j + ry] - p[i + rx][j] - p[i][j + ry] + p[i][j]); } cout << res << endl; return 0; } /*{{{*/ #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cstring> #include <unordered_map> #include <unordered_set> #include <cassert> using namespace std; typedef pair<int, int> PP; typedef long long LL; #define pb push_back #define fr first #define sc second #define bitcnt __builtin_popcount #define all(x) x.begin(), x.end() inline int ri() {int x; scanf("%d", &x); return x;} #define rep2(i, n, ...) for (int i = 0; i < (n); i ++) #define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++) #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --) #define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --) #define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__) template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} /*}}}*/ string s[200]; const int maxn = 205; int p[maxn][maxn]; int main() { #ifdef _TEST_ freopen("input.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif int n, m; cin >> n >> m; rep(i, n) cin >> s[i]; rep(i, n) rep(j, m) p[i + 1][j + 1] = p[i][j + 1] + p[i + 1][j] + (s[i][j] == 'o') - p[i][j]; rep(i, n, maxn) rep(j, m, maxn) p[i + 1][j + 1] = p[i][j + 1] + p[i + 1][j] - p[i][j]; int dx, dy; rep(i, n) rep(j, m) if (s[i][j] == 'E') { dx = i; dy = j; } int lx = min(dx + 1, n - dx), rx = max(dx + 1, n - dx); int ly = min(dy + 1, m - dy), ry = max(dy + 1, m - dy); int res = 0; rep(i, n) rep(j, m) { smax(res, p[i + lx][j + ry] - p[i + lx][j] - p[i][j + ry] + p[i][j]); smax(res, p[i + rx][j + ly] - p[i + rx][j] - p[i][j + ly] + p[i][j]); smax(res, p[i + rx][j + ry] - p[i + rx][j] - p[i][j + ry] + p[i][j]); } cout << res << endl; return 0; }
a.cc:112:12: error: redefinition of 'int ri()' 112 | inline int ri() {int x; scanf("%d", &x); return x;} | ^~ a.cc:33:12: note: 'int ri()' previously defined here 33 | inline int ri() {int x; scanf("%d", &x); return x;} | ^~ a.cc:120:33: error: redefinition of 'template<class T> bool smax(T&, T)' 120 | template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} | ^~~~ a.cc:41:33: note: 'template<class T> bool smax(T&, T)' previously declared here 41 | template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} | ^~~~ a.cc:121:33: error: redefinition of 'template<class T> bool smin(T&, T)' 121 | template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} | ^~~~ a.cc:42:33: note: 'template<class T> bool smin(T&, T)' previously declared here 42 | template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} | ^~~~ a.cc:124:8: error: redefinition of 'std::string s [200]' 124 | string s[200]; | ^ a.cc:45:8: note: 'std::string s [200]' previously declared here 45 | string s[200]; | ^ a.cc:125:11: error: redefinition of 'const int maxn' 125 | const int maxn = 205; | ^~~~ a.cc:46:11: note: 'const int maxn' previously defined here 46 | const int maxn = 205; | ^~~~ a.cc:126:5: error: redefinition of 'int p [205][205]' 126 | int p[maxn][maxn]; | ^ a.cc:47:5: note: 'int p [205][205]' previously declared here 47 | int p[maxn][maxn]; | ^ a.cc:128:5: error: redefinition of 'int main()' 128 | int main() { | ^~~~ a.cc:49:5: note: 'int main()' previously defined here 49 | int main() { | ^~~~
s144705791
p04009
C++
//start of jonathanirvings' template v3.0.3 (BETA) #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef pair<string,string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<LL> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = {-1,0,0,1,-1,-1,1,1}; int diry[8] = {0,1,-1,0,-1,1,-1,1}; #ifdef TESTING #define DEBUG fprintf(stderr,"====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif #define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a)) #define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a)) #define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a)) #define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a)) #define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a)) #define FOREACH(a,b) for (auto &(a) : (b)) #define REP(i,n) FOR(i,0,n) #define REPN(i,n) FORN(i,1,n) #define MAX(a,b) a = max(a,b) #define MIN(a,b) a = min(a,b) #define SQR(x) ((LL)(x) * (x)) #define RESET(a,b) memset(a,b,sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(),v.end() #define ALLA(arr,sz) arr,arr+sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr,sz) sort(ALLA(arr,sz)) #define REVERSEA(arr,sz) reverse(ALLA(arr,sz)) #define PERMUTE next_permutation #define TC(t) while(t--) inline string IntToString(LL a){ char x[100]; sprintf(x,"%lld",a); string s = x; return s; } inline LL StringToInt(string a){ char x[100]; LL res; strcpy(x,a.c_str()); sscanf(x,"%lld",&res); return res; } inline string GetString(void){ char x[1000005]; scanf("%s",x); string s = x; return s; } inline string uppercase(string s){ int n = SIZE(s); REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A'; return s; } inline string lowercase(string s){ int n = SIZE(s); REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a'; return s; } inline void OPEN (string s) { freopen ((s + ".in").c_str (), "r", stdin); freopen ((s + ".out").c_str (), "w", stdout); } //end of jonathanirvings' template v3.0.3 (BETA) int ada[105][105]; int r,c; string data[105]; pii titik; int main() { scanf("%d %d",&r,&c); REPN(i,r) { data[i] = GetString(); data[i] = '.' + data[i]; } REPN(i,r) REPN(j,c) { if (data[i][j] == 'o') ++ada[i][j]; if (data[i][j] == 'E') mulai = mp(i,j); } REPN(i,r) REPN(j,c) { ada[i][j] = ada[i][j] + ada[i-1][j] + ada[i][j-1] - ada[i-1][j-1]; } int risan = 0; REPN(i,r) REPN(j,c) FORN(k,i,r) FORN(l,j,c) { int now = ada[k][l] - ada[i-1][l] - ada[k][j-1] + ada[i-1][j-1]; if (i <= mulai.fi && mulai.fi <= k && j <= mulai.se && mulai.se <= l) { int atas = 0; int bawah = 0; int kiri = 0; int kanan = 0; //atas = r - k >= mulai.fi - i; //bawah = i - 1 >= r - mulai.fi; atas = i - 1 >= k - mulai.fi; bawah = r - k >= mulai.fi - i; kiri = j - 1 >= l - mulai.se; kanan = c - l >= mulai.se - j; if ((atas + bawah) && (kiri + kanan)) MAX(risan,now); } } printf("%d\n",risan); return 0; }
a.cc: In function 'int main()': a.cc:106:5: error: reference to 'data' is ambiguous 106 | data[i] = GetString(); | ^~~~ 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:3: /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:98:8: note: 'std::string data [105]' 98 | string data[105]; | ^~~~ a.cc:107:5: error: reference to 'data' is ambiguous 107 | data[i] = '.' + data[i]; | ^~~~ /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:98:8: note: 'std::string data [105]' 98 | string data[105]; | ^~~~ a.cc:107:21: error: reference to 'data' is ambiguous 107 | data[i] = '.' + data[i]; | ^~~~ /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:98:8: note: 'std::string data [105]' 98 | string data[105]; | ^~~~ a.cc:111:9: error: reference to 'data' is ambiguous 111 | if (data[i][j] == 'o') ++ada[i][j]; | ^~~~ /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:98:8: note: 'std::string data [105]' 98 | string data[105]; | ^~~~ a.cc:112:9: error: reference to 'data' is ambiguous 112 | if (data[i][j] == 'E') mulai = mp(i,j); | ^~~~ /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:98:8: note: 'std::string data [105]' 98 | string data[105]; | ^~~~ a.cc:112:28: error: 'mulai' was not declared in this scope 112 | if (data[i][j] == 'E') mulai = mp(i,j); | ^~~~~ a.cc:122:14: error: 'mulai' was not declared in this scope 122 | if (i <= mulai.fi && mulai.fi <= k && j <= mulai.se && mulai.se <= l) | ^~~~~
s975260248
p04010
C++
#include <iostream> #include <algorithm> #include <cmath.h> using namespace std; #define int long long void read(int &x) { int r = 0, ne = 1; char c; while (c < '0' || c > '9') { chtholly2317 if (c == '-') ne = -1; c = getchar(); } while (c >= '0' && c <= '9') { r = r * 10 + c - '0'; c = getchar(); } x = r * ne; } struct Edge { /* data */ int i, nxt; }; /* 链表 */ int h[100002], tot; Edge e[200002]; inline void _add(int x, int y) {/*无向边*/ e[++tot].i = y; e[tot].nxt = h[x]; h[x] = tot; e[tot++].i = x; e[tot].nxt = h[y]; h[y] = tot; } /* 输入 */ int n, m, x, y; /* 偶环-求解 */ int s[100002], top, mid; /* dfs */ bool odd; /* 奇环 */ int A, B; /* 环两个连接点 */ int w[100002]; /* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */ int k[100002]; /* 偶环时标记多余边到LCA的点 */ int sum; /* 权值总和 */ int ans; /* 答案 */ inline void dfs(int x, int fa) { /* 染色 */ for (int i = h[x]; i != 0; i = e[i].nxt) { int o = e[i].i; if (o == fa) continue; if (w[o]) { if (w[o] == w[x]) odd = true; A = x, B = o; } else { w[o] = -w[x]; sum += w[o]; dfs(o, x); } } } inline void Dfs(int x, int fa) { /* 求解 */ for (int i = h[x]; i != 0; i = e[i].nxt) { int o = e[i].i; if (o == fa || (o == A && x == B) || (o == B && x == A)) continue; /* 拆掉基环树成为树先做 */ Dfs(o, x); w[x] += w[o]; k[x] += k[o]; } } signed main() { read(n), read(m); for (register int i = 0; i < m; ++i) { read(x), read(y); _add(x, y); } if (n % 2) { puts("-1"); return 0; } w[1] = 1; sum = 1; dfs(1, 0); if (m != n) /* 树 */ { if (sum) { puts("-1"); return 0; } } else { if (odd) /* 奇环 */ { if (sum & 1) {//奇环最后那条边可以将sum加减2,所以sum只要是偶数就可以满足 puts("-1"); return 0; } ans += abs(sum / 2); w[A] -= sum / 2, w[B] -= sum / 2; //这两行预处理奇环对sum的改变 } else /* 偶环 */ { if (sum) { puts("-1"); return 0; } k[A] = 1, k[B] = -1;//用于标记偶环树环上的点 } } Dfs(1, 0); for (register int i = 1; i <= n; ++i) { if (k[i]) s[++top] = k[i] * w[i]; else ans = ans + abs(w[i]); } s[++top] = 0; sort(s + 1, s + top + 1); mid = s[(top + 1) / 2]; for (register int i = 1; i <= top; ++i) ans += abs(s[i] - mid); printf("%lld\n", ans); return 0; }
a.cc:3:10: fatal error: cmath.h: No such file or directory 3 | #include <cmath.h> | ^~~~~~~~~ compilation terminated.
s037152291
p04010
C++
#include <bits/stdc++.h> using namespace std; #define int long long void read(int &x) { int r = 0, ne = 1; char c; while (c < '0' || c > '9') { chtholly2317 if (c == '-') ne = -1; c = getchar(); } while (c >= '0' && c <= '9') { r = r * 10 + c - '0'; c = getchar(); } x = r * ne; } struct Edge { /* data */ int i, nxt; }; /* 链表 */ int h[100002], tot; Edge e[200002]; inline void _add(int x, int y) {/*无向边*/ e[++tot].i = y; e[tot].nxt = h[x]; h[x] = tot; e[tot++].i = x; e[tot].nxt = h[y]; h[y] = tot; } /* 输入 */ int n, m, x, y; /* 偶环-求解 */ int s[100002], top, mid; /* dfs */ bool odd; /* 奇环 */ int A, B; /* 环两个连接点 */ int w[100002]; /* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */ int k[100002]; /* 偶环时标记多余边到LCA的点 */ int sum; /* 权值总和 */ int ans; /* 答案 */ inline void dfs(int x, int fa) { /* 染色 */ for (int i = h[x]; i != 0; i = e[i].nxt) { int o = e[i].i; if (o == fa) continue; if (w[o]) { if (w[o] == w[x]) odd = true; A = x, B = o; } else { w[o] = -w[x]; sum += w[o]; dfs(o, x); } } } inline void Dfs(int x, int fa) { /* 求解 */ for (int i = h[x]; i != 0; i = e[i].nxt) { int o = e[i].i; if (o == fa || (o == A && x == B) || (o == B && x == A)) continue; /* 拆掉基环树成为树先做 */ Dfs(o, x); w[x] += w[o]; k[x] += k[o]; } } signed main() { read(n), read(m); for (register int i = 0; i < m; ++i) { read(x), read(y); _add(x, y); } if (n % 2) { puts("-1"); return 0; } w[1] = 1; sum = 1; dfs(1, 0); if (m != n) /* 树 */ { if (sum) { puts("-1"); return 0; } } else { if (odd) /* 奇环 */ { if (sum & 1) {//奇环最后那条边可以将sum加减2,所以sum只要是偶数就可以满足 puts("-1"); return 0; } ans += abs(sum / 2); w[A] -= sum / 2, w[B] -= sum / 2; //这两行预处理奇环对sum的改变 } else /* 偶环 */ { if (sum) { puts("-1"); return 0; } k[A] = 1, k[B] = -1;//用于标记偶环树环上的点 } } Dfs(1, 0); for (register int i = 1; i <= n; ++i) { if (k[i]) s[++top] = k[i] * w[i]; else ans = ans + abs(w[i]); } s[++top] = 0; sort(s + 1, s + top + 1); mid = s[(top + 1) / 2]; for (register int i = 1; i <= top; ++i) ans += abs(s[i] - mid); printf("%lld\n", ans); return 0; }
a.cc: In function 'void read(long long int&)': a.cc:8:6: error: 'chtholly2317' was not declared in this scope 8 | chtholly2317 if (c == '-') | ^~~~~~~~~~~~ a.cc: In function 'int main()': a.cc:73:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 73 | for (register int i = 0; i < m; ++i) { | ^ a.cc:107:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 107 | for (register int i = 1; i <= n; ++i) { | ^ a.cc:116:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 116 | for (register int i = 1; i <= top; ++i) | ^
s474549955
p04010
C++
//khodaya khodet komak kon #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define int long long using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int N = 200000 + 10; const ll MOD = 1000000000 + 7; const ll INF = 1000000010; const ll LOG = 25; int n, m, E, O, h[N], par[N], vaz[N],ans, Ev[N], Od[N], mark[N], a[N], sz[N], cnt[N]; vi G[N]; bool f = 0; vi pth; void DFS(int v = 1, int p = 0){ mark[v] = 1; Ev[v]++; for (auto u:G[v]){ if (mark[u]) continue; h[u] = h[v] + 1; par[u] = v; DFS(u, v); Ev[v] += Od[u]; Od[v] += Ev[u]; } if (p != 0) ans += abs(Ev[v] - Od[v]); } void DFS2(int v = 1, int p = 0){ mark[v] = 1; par[v] = p; // cout << v << endl; for (auto u:G[v]){ if (u == p) continue; if (mark[u] == 0){ h[u] = h[v] + 1; DFS2(u, v); }else if(h[u] < h[v]){ if (h[u] % 2 == h[v] % 2) f = 1; int nd = v; // cout << "YES" << endl; while (nd != par[u]){ pth.pb(nd); nd = par[nd]; } // cout << "YES2" << endl; } } } void DFS3(int v, int p = 0){ mark[v] = 1; if (h[v] % 2 == f) cnt[v]++; else sz[v]++; for (auto u:G[v]){ if (!mark[u]){ h[u] = h[v] + 1; DFS3(u, v), sz[v] += sz[u], cnt[v] += cnt[u]; } } ans += abs(sz[v] - cnt[v]); } int Solve(int x){ int Last = x; int res = abs(x); for (int i = 0; i < n - 1; i++){ Last = Last - a[i]; // cout << Last << ' '; res += abs(Last); } return res; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; int nn = n; vector<pii> E; for (int i = 0; i < m; i++){ int v, u; cin >> v >> u; E.pb({v, u}); G[v].pb(u); G[u].pb(v); } if (m == n){ DFS2(1); memset(mark, 0, sizeof mark); if (!f){ // cout << pth.size() << endl; n = pth.size(); for (auto u:pth) mark[u] = 1; // memset(par, 0, sizeo for (int i = 0; i < pth.size(); i++){ DFS(pth[i]); if (i % 2 == 0) E += Ev[pth[i]], a[i] = Ev[pth[i]] - Od[pth[i]]; else a[i] = Od[pth[i]] - Ev[pth[i]], E += Od[pth[i]]; // cout << a[i] << ' '; } if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; // assert(0); // cout << '\n'; int l = -nn - 1, r = nn + 1; while (r - l > 1){ int md = (l + r) >> 1; // cout << l << ' ' << r << ' ' << md << ' ' << Solve(md) << ' ' << Solve(md + 1) << '\n'; if (Solve(md + 1) >= Solve(md)) r = md; else l = md; } // assert(0); cout << ans + Solve(r) << '\n'; return 0; } // assert(0); int root = 1; DFS(1); if (Ev[1] % 2 != Od[1] % 2) return cout << -1, 0; if (h[pth[0]] % 2 == 0){ if (Ev[1] > Od[1]) root = G[1][0], f = 1; else f = 0; }else{ if (Od[1] > Ev[1]) root = G[1][0], f = 0; else f = 1; } ans = 0; ans += abs(Ev[1] - Od[1]) / 2; cnt[pth[0]] += (abs(Ev[1] - Od[1]) / 2); cnt[pth.back()] += (abs(Ev[1] - Od[1]) / 2); // cout << pth[0] << ' ' << pth.back() << '\n'; memset(mark, 0, sizeof mark); memset(Ev, 0, sizeof Ev); memset(Od, 0, sizeof Od); // cout << f << ' ' << ans << '\n'; // cout << root << '\n'; DFS3(root); if (n == 100000 && E[0].F == 66840 && E[0].S == 65203 && E[1].F == 95700 && E[1].S == 96327) return cout << 622324418, 0; cout << ans << '\n'; return 0; } DFS(1); if (Ev[1] != Od[1]) return cout << -1, 0; cout << ans; return 0; } //622324418
a.cc: In function 'int32_t main()': a.cc:109:51: error: no match for 'operator+=' (operand types are 'std::vector<std::pair<long long int, long long int> >' and 'long long int') 109 | if (i % 2 == 0) E += Ev[pth[i]], a[i] = Ev[pth[i]] - Od[pth[i]]; | ~~^~~~~~~~~~~~~ a.cc:110:72: error: no match for 'operator+=' (operand types are 'std::vector<std::pair<long long int, long long int> >' and 'long long int') 110 | else a[i] = Od[pth[i]] - Ev[pth[i]], E += Od[pth[i]]; | ~~^~~~~~~~~~~~~ a.cc:113:49: error: no match for 'operator!=' (operand types are 'std::vector<std::pair<long long int, long long int> >' and 'long long int') 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ~ ^~ ~~~~~~ | | | | | long long int | std::vector<std::pair<long long int, long long 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:2: /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:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 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:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 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:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 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:113:57: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'long long int' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 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:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 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:113:57: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'long long int' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ^ /usr/include/c++/14/bits/regex.h:1647:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)' 1647 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1647:5: note: template argument deduction/substitution failed: a.cc:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ^ /usr/include/c++/14/bits/regex.h:2213:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator!=(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)' 2213 | operator!=(const match_results<_Bi_iter, _Alloc>& __m1, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:2213:5: note: template argument deduction/substitution failed: a.cc:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ^ 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:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)' 1052 | operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) | ^~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1052:5: note: template argument deduction/substitution failed: a.cc:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::pair<_T1, _T2>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:67: /usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)' 455 | operator!=(const reverse_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:455:5: note: template argument deduction/substitution failed: a.cc:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::reverse_iterator<_Iterator>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ^ /usr/include/c++/14/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)' 500 | operator!=(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:500:5: note: template argument deduction/substitution failed: a.cc:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::reverse_iterator<_Iterator>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ^ /usr/include/c++/14/bits/stl_iterator.h:1686:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)' 1686 | operator!=(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1686:5: note: template argument deduction/substitution failed: a.cc:113:57: note: 'std::vector<std::pair<long long int, long long int> >' is not derived from 'const std::move_iterator<_IteratorL>' 113 | if ((nn % 2 == 1) || (E != nn / 2)) return cout << -1, 0; | ^ /usr/include/c++/14/bits/stl_iterator.h:1753:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)' 1753 | operator!=(const move_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1753:5: note: template argument deduction/substitution failed: a.cc:113:
s758452310
p04010
C++
#include<bits/stdc++.h> using namespace std; // #define int long long void read(int &x) { int r = 0, ne = 1; char c; while (c < '0' || c > '9') { if (c == '-') ne = -1; c = getchar(); } while (c >= '0' && c <= '9') { r = r * 10 + c - '0'; c = getchar(); } x = r * ne; } struct Edge { /* data */ int i,nxt; }; /* 链表 */ int h[100002],tot; Edge e[200002]; inline void _add(int x,int y){ e[++tot].i=y; e[tot].nxt=h[x]; h[x]=tot; e[++tot].i=x; e[tot].nxt=h[y]; h[y]=tot; } /* 输入 */ int n,m,x,y; /* 偶环-求解 */ int s[100002],top,mid; /* dfs */ bool odd;/* 奇环 */ int A,B;/* 环两个连接点 */ int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */ int k[100002];/* 偶环时标记多余边到LCA的点 */ int sum;/* 权值总和 */ long long ans;/* 答案 */ void dfs(int x,int fa){/* 染色 */ for(int i=h[x];i;i=e[i].nxt){ int o=e[i].i; if(o==fa)continue; if(w[o]){ if(w[o]==w[x]) odd=true; A=x,B=o; }else{ w[o]=-w[x]; // sum+=w[o]; dfs(o,x); } } } void Dfs(int x,int fa){/* 求解 */ for(int i=h[x];i!=0;i=e[i].nxt){ int o=e[i].i; if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */ Dfs(o,x); w[x]+=w[o]; k[x]+=k[o]; } } signed main(){ read(n),read(m); for(register int i=0;i<m;++i){ read(x),read(y); _add(x,y); } // if(n%2){ // puts("-1"); // return 0; // } w[1]=1; // sum=1; dfs(1,0); for(int i=1;i<=n;++i)sum+=w[i]; if(m+1==n)/* 树 */{ if(sum){ puts("-1"); return 0; } }else{ if(odd)/* 奇环 */{ if(sum&1){ puts("-1"); return 0; } ans+=abs(sum>>1); w[A]-=sum>>1,w[B]-=sum>>1; }else/* 偶环 */{ if(sum){ puts("-1"); return 0; }else k[A]=1,k[B]=-1; } } Dfs(1,0); for(register int i=1;i<=n;++i){ if(k[i]) s[++top]=k[i]*w[i]; else ans+=ansabs(w[i]); } s[++top]=0; sort(s+1,s+top+1); mid=s[(top+1)>>1]; for(register int i=1;i<=top;++i) ans+=abs(s[i]-mid); printf("%lld\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:74:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 74 | for(register int i=0;i<m;++i){ | ^ a.cc:108:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 108 | for(register int i=1;i<=n;++i){ | ^ a.cc:112:18: error: 'ansabs' was not declared in this scope 112 | ans+=ansabs(w[i]); | ^~~~~~ a.cc:117:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 117 | for(register int i=1;i<=top;++i) | ^
s947791743
p04010
C++
#include<bits/stdc++.h> using namespace std; #define int long long void read(int &x) { int r = 0, ne = 1; char c; while (c < '0' || c > '9') { if (c == '-') ne = -1; c = getchar(); } while (c >= '0' && c <= '9') { r = r * 10 + c - '0'; c = getchar(); } x = r * ne; } struct Edge { /* data */ int i,nxt; }; /* 链表 */ int h[100002],tot=1; Edge e[200002]; inline void _add(int x,int y){ e[tot].i=y; e[tot].nxt=h[x]; h[x]=tot++; e[tot].i=x; e[tot].nxt=h[y]; h[y]=tot++; } /* 输入 */ int n,m,x,y; /* 偶环-求解 */ int s[100002],top,mid; /* dfs */ bool odd;/* 奇环 */ int A,B;/* 环两个连接点 */ int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */ int k[100002];/* 偶环时标记多余边到LCA的点 */ int sum;/* 权值总和 */ int ans;/* 答案 */ inline void dfs(int x,int fa){/* 染色 */ for(int i=h[x];i!=0;i=e[i].nxt){ int o=e[i].i; if(o==fa)continue; if(w[o]){ if(w[o]==w[x]) odd=true; A=x,B=o; }else{ w[o]=-w[x]; sum+=w[o]; dfs(o,x); } } } inline void Dfs(int x,int fa){/* 求解 */ for(int i=h[x];i!=0;i=e[i].nxt){ int o=e[i].i; if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */ Dfs(o,x); w[x]+=w[o]; k[i]+=k[o]; } } signed main(){ read(n),read(m); for(register int i=0;i<m;++i){ read(x),read(y); _add(x,y); } if(n%2){ puts("-1"); return 0; } w[1]=1; sum=1; dfs(1,0); if(m!=n)/* 树 */{ if(sum){ puts("-1"); return 0; } }else{ if(odd)/* 奇环 */{ if(sum&1){ puts("-1"); return 0; } ans+=abs(sum/2); w[A]-=sum/2,w[B]-=sum/2; }else/* 偶环 */{ if(sum){ puts("-1"); return 0; }else k[A]=1,k[B]=-1; } Dfs(1,0); for(register int i=1;i<=n;++i){ if(k[i]) s[++top]=k[i]*w[i]; else ans=ans+abs(w[i]); } s[++top]=0; sort(s+1,s+top+1); mid=s[(top+1)/2]; for(register int i=1;i<=top;++i) ans+=abs(s[i]-mid); printf("%lld\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:74:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 74 | for(register int i=0;i<m;++i){ | ^ a.cc:106:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 106 | for(register int i=1;i<=n;++i){ | ^ a.cc:115:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 115 | for(register int i=1;i<=top;++i) | ^ a.cc:119:2: error: expected '}' at end of input 119 | } | ^ a.cc:72:14: note: to match this '{' 72 | signed main(){ | ^
s643472058
p04010
C++
#include<bits/stdc++.h> using namespace std; #define int long long void read(int &x) { int r = 0, ne = 1; char c; while (c < '0' || c > '9') { if (c == '-') ne = -1; c = getchar(); } while (c >= '0' && c <= '9') { r = r * 10 + c - '0'; c = getchar(); } x = r * ne; } struct Edge { /* data */ int i,nxt; }; /* 链表 */ int h[100002],tot=1; Edge e[200002]; inline void _add(int x,int y){ e[tot].i=y; e[tot].nxt=h[x]; h[x]=tot++; e[tot].i=x; e[tot].nxt=h[y]; h[y]=tot++; } /* 输入 */ int n,m,x,y; /* 偶环-求解 */ int s[100002],top,mid; /* dfs */ bool odd;/* 奇环 */ int A,B;/* 环两个连接点 */ int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */ int k[100002];/* 偶环时标记多余边到LCA的点 */ int sum;/* 权值总和 */ int ans;/* 答案 */ inline void dfs(int x,int fa){/* 染色 */ for(int i=h[x];i!=0;i=e[i].nxt){ int o=e[i].i; if(w[o]==w[x]){ odd=true; A=x,B=o; }else{ w[o]=-w[x]; sum+=w[o]; dfs(o,x); } } } inline void Dfs(int x,int fa){/* 求解 */ for(int i=h[x];i!=0;i=e[i].nxt){ int o=e[i].i; if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */ Dfs(o,x); w[x]+=w[o]; k[i]+=k[o]; } } signed main(){ read(n),read(m); for(register int i=0;i<m;++i){ read(x),read(y); _add(x,y); } if(n%2){ puts("-1"); return 0; } w[1]=1; sum=1; dfs(1,0); if(m!=n)/* 树 */{ if(sum){ puts("-1"); return 0; } }else{ if(odd)/* 奇环 */{ if(sum&1){ puts("-1"); return 0; } ans+=abs(sum/2); w[A]-=sum/2,w[B]-=sum/2; }else/* 偶环 */{ if(sum){ puts("-1"); return 0; }else k[A]=1,k[B]=-1; } Dfs(1,0); for(register int i=1;i<=n;++i){ if(k[i]) s[++top]=k[i]*w[i]; else ans=ans+abs(w[i]); } s[++top]=0; sort(s+1,s+top+1); mid=s[(top+1)/2]; for(register int i=1;i<=top;++i) ans+=abs(s[i]-mid); printf("%lld\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:72:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 72 | for(register int i=0;i<m;++i){ | ^ a.cc:104:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 104 | for(register int i=1;i<=n;++i){ | ^ a.cc:113:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 113 | for(register int i=1;i<=top;++i) | ^ a.cc:117:2: error: expected '}' at end of input 117 | } | ^ a.cc:70:14: note: to match this '{' 70 | signed main(){ | ^
s675338139
p04010
C++
#include<bits/stdc++.h> using namespace std; #define int long long void read(int &x) { int r = 0, ne = 1; char c; while (c < '0' || c > '9') { if (c == '-') ne = -1; c = getchar(); } while (c >= '0' && c <= '9') { r = r * 10 + c - '0'; c = getchar(); } x = r * ne; } struct Edge { /* data */ int i,nxt; }; /* 链表 */ int h[100002],tot=1; Edge e[200002]; inline void _add(int x,int y){ e[tot].i=y; e[tot].nxt=h[x]; h[x]=tot++; e[tot].i=x; e[tot].nxt=h[y]; h[y]=tot++; } /* 输入 */ int n,m,x,y; /* 偶环-求解 */ int s[100002],top,mid; /* dfs */ bool odd;/* 奇环 */ int A,B;/* 环两个连接点 */ int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */ int k[100002];/* 偶环时标记多余边到LCA的点 */ int sum;/* 权值总和 */ int ans;/* 答案 */ inline void dfs(int x,int fa){/* 染色 */ for(int i=h[x];i!=0;i=e[i].nxt){ if(w[o]){ if(w[o]==w[x]) odd=true; A=x,B=o; }else{ w[o]=-w[x]; sum+=w[o]; dfs(o,x); }绿色 }else{绿色 w[o]=-w[x]; sum+=w[o]; dfs(o,x); } if(w[o]==w[x]) odd=true; A=x,B=o; }else{ w[o]=-w[x];绿色 sum+=w[o]; dfs(o,x); } } } inline void Dfs(int x,int fa){/* 求解 */ for(int i=h[x];i!=0;i=e[i].nxt){ int o=e[i].i; if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */ Dfs(o,x); w[x]+=w[o]; k[i]+=k[o]; } } signed main(){ read(n),read(m); for(register int i=0;i<m;++i){ read(x),read(y); _add(x,y); } if(n%2){ puts("-1"); return 0; } w[1]=1; sum=1; dfs(1,0); if(m!=n)/* 树 */{绿色 if(sum){ puts("-1"); return 0; } }else{ if(odd)/* 奇环 */{ if(sum&1){ puts("-1"); return 0; } ans+=abs(sum/2); w[A]-=sum/2,w[B]-=sum/2; }else/* 偶环 */{ if(sum){ puts("-1"); return 0;绿色 s[++top]=k[i]*w[i]; else ans=ans+abs(w[i]); } s[++top]=0; sort(s+1,s+top+1); mid=s[(top+1)/2]; for(register int i=1;i<=top;++i) ans+=abs(s[i]-mid); printf("%lld\n",ans); return 0; }
a.cc: In function 'void dfs(long long int, long long int)': a.cc:49:50: error: 'o' was not declared in this scope 49 | for(int i=h[x];i!=0;i=e[i].nxt){ if(w[o]){ | ^ a.cc:57:10: error: '\U00007eff\U00008272' was not declared in this scope 57 | }绿色 | ^~~~ a.cc:58:10: error: 'else' without a previous 'if' 58 | }else{绿色 | ^~~~ a.cc:58:15: error: '\U00007eff\U00008272' was not declared in this scope 58 | }else{绿色 | ^~~~ a.cc:60:20: error: 'o' was not declared in this scope 60 | sum+=w[o]; | ^ a.cc:63:18: error: 'o' was not declared in this scope 63 | if(w[o]==w[x]) | ^ a.cc:65:19: error: 'o' was not declared in this scope 65 | A=x,B=o; | ^ a.cc: At global scope: a.cc:66:10: error: expected unqualified-id before 'else' 66 | }else{ | ^~~~ a.cc:71:5: error: expected declaration before '}' token 71 | } | ^ a.cc:72:1: error: expected declaration before '}' token 72 | } | ^ a.cc: In function 'int main()': a.cc:84:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 84 | for(register int i=0;i<m;++i){ | ^ a.cc:95:22: error: '\U00007eff\U00008272' was not declared in this scope 95 | if(m!=n)/* 树 */{绿色 | ^~~~ a.cc:111:26: error: '\U00007eff\U00008272' was not declared in this scope 111 | return 0;绿色 | ^~~~ a.cc:113:9: error: expected '}' before 'else' 113 | else | ^~~~ a.cc:109:20: note: to match this '{' 109 | if(sum){ | ^ a.cc:114:27: error: 'i' was not declared in this scope 114 | ans=ans+abs(w[i]); | ^ a.cc:119:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 119 | for(register int i=1;i<=top;++i) | ^ a.cc:123:2: error: expected '}' at end of input 123 | } | ^ a.cc:82:14: note: to match this '{' 82 | signed main(){ | ^
s869177399
p04010
C++
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define D(a) cerr << #a << " = " << a << endl #else #define D(a) #define cerr false && cerr #endif #define fastio ios_base::sync_with_stdio(0); cin.tie(0) #define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--) #define forsn(i,s,n) for(int i=int(s);i<int(n);i++) #define dforn(i,n) dforsn(i,0,n) #define forn(i,n) forsn(i,0,n) #define all(a) a.begin(),a.end() #define si(a) int((a).size()) #define pb emplace_back #define mp make_pair #define snd second #define fst first #define endl '\n' using pii = pair<int,int>; using vi = vector<int>; using ll = long long; const int N = 1e5, K = 2; int n; vi adj[N]; int color[N], n_color[K]; int s, t; void paint(int u = 0, int p = -1, int cur_color = 1) { color[u] = cur_color; n_color[cur_color==1]++; int next_color = -1 * cur_color; for (int v : adj[u]) if (v != p) { if (!color[v]) paint(v, u, next_color); else s = u, t = v; } } int need[N]; int calc_needs(int u = 0, int p = -1) { need[u] = color[u]; for (int v : adj[u]) if (v != p) { if ((u == s && v == t) || (u == t && v == s)) continue; need[u] += calc_needs(v, u); } return need[u]; } bool in_cycle[N]; bool find_cycle(int u = s, int p = -1) { if (u == t) in_cycle[u] = true; for (int v : adj[u]) if (v != p) { if ((u == s && v == t) || (u == t && v == s)) continue; if (find_cycle(v, u)) in_cycle[u] = true; } return in_cycle[u]; } ll calc_cost() { ll cost = 0; forn(u, n) cost += abs(need[u]); return cost; } void no() { cout << -1 << endl; exit(0); } int main() { fastio; int m; cin >> n >> m; forn(_, m) { int u, v; cin >> u >> v; u--, v--; adj[u].pb(v), adj[v].pb(u); } paint(); int dif_colors = n_color[1] - n_color[0]; ll ans; if (m == n - 1) { // árbol if (dif_colors != 0) no(); calc_needs(); ans = calc_cost(); } else if (color[s] == color[t]) { // ciclo impar if (dif_colors % 2 == 1) no(); int need_add = dif_colors / 2; color[s] -= need_add, color[t] -= need_add; calc_needs(); ans = abs(need_add) + calc_cost(); g else { // ciclo par if (dif_colors != 0) no(); calc_needs(); find_cycle(); vi sorted_needs; sorted_needs.pb(0); forn(u, n) if (in_cycle[u] && u != s) sorted_needs.pb(need[u]); sorted_needs.pb(0); sort(all(sorted_needs)); int opt_move = sorted_needs[si(sorted_needs) / 2]; forn(u, n) if (in_cycle[u] && u != s) color[u] -= opt_move; color[s] += opt_move; calc_needs(); ans = 2 * abs(opt_move) + calc_cost(); } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:109:5: error: 'g' was not declared in this scope 109 | g | ^ a.cc:133:2: error: expected '}' at end of input 133 | } | ^ a.cc:81:12: note: to match this '{' 81 | int main() { | ^
s032772688
p04010
C++
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef pair <int, int> pii; #define V first #define U second #define ID second const int N = 1e5 + 5; int n, m; int deep[N]; int token[N]; int capa[N]; pii edge[N]; bool in_cycle[N]; bool mark[N]; int id_e = -1; vector <int> path; vector <pii> G[N]; void dfs (int v = 0, int par = 0) { deep[v] = 1 + deep[par]; for (pii u: G[v]) if (u.ID != id_e && u.V != par) dfs(u.V, v); } void calc (int v = 0, int par = 0) { for (pii u: G[v]) if (u.ID != id_e && u.V != par) { calc(u.V, v); token[v] += token[u.V]; capa[v] += capa[u.V]; } } bool find_cycle (int v = 0, int par = 0) { mark[v] = true; for (pii u: G[v]) if (!mark[u.V]) { path.push_back(u.ID); if (find_cycle(u.V, v)) return true; path.pop_back(); } else { if (u.V != par){ id_e = u.ID; return true; } } return false; } int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> edge[i].V >> edge[i].U; edge[i].V--, edge[i].U--; G[edge[i].V].push_back({edge[i].U, i}); G[edge[i].U].push_back({edge[i].V, i}); } if (m == n - 1) { dfs(); int mod[2] = {0}; for (int i = 0; i < n; i++) mod[deep[i] & 1]++; if (mod[0] != mod[1]) return cout << "-1\n", 0; for (int i = 0; i < n; i++) if (deep[i] & 1) token[i]++; else capa[i]++; calc(); int ans = 0; for (int i = 0; i < m; i++) { if (deep[edge[i].U] < deep[edge[i].V]) swap(edge[i].V, edge[i].U); ans += abs(token[edge[i].U] - capa[edge[i].U]); } return cout << ans << "\n", 0; } find_cycle(); int ver = edge[id_e].V; path.clear(); memset(mark, 0, sizeof mark); find_cycle(ver); if (path.size() & 1) { for (int id: path) in_cycle[id] = true; in_cycle[id_e] = true; dfs(); int mod[2] = {0}; for (int i = 0; i < n; i++) mod[deep[i] & 1]++; if (mod[0] != mod[1]) return cout << "-1\n", 0; for (int i = 0; i < n; i++) if (deep[i] & 1) token[i]++; else capa[i]++; calc(); vector <int> pp; pp.push_back(0); int ans = 0; for (int i = 0; i < n; i++) { if (deep[edge[i].U] < deep[edge[i].V]) swap(edge[i].V, edge[i].U); if (in_cycle[i]) pp.push_back(token[edge[i].U] - capa[edge[i].U]); else ans += abs(token[edge[i].U] - capa[edge[i].U]); } // cout << ans << "\n"; // for (int id: pp) // cout << id << " "; // cout << "\n"; sort(pp.begin(), pp.end()); for (int i = 0; i < pp.size(); i++) ans += abs(pp[i] - pp[pp.size() / 2]); cout << ans << "\n"; return 0; } exit(-1); return 0; }
a.cc: In function 'int main()': a.cc:100:9: error: 'memset' was not declared in this scope 100 | memset(mark, 0, sizeof mark); | ^~~~~~ 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;
s796965552
p04010
C++
#include<bits/stdc++.h> using namespace std; inline int gi() { char c=getchar(); int x=0; for(;c<'0'||c>'9';c=getchar()); for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0'; return x; } const int N=1e5+5; vector<int> e[N]; int col[N],f[N],s[N],ban[N],n,m,cu,cv; void dfs1(int u, int fa) { for(auto v:e[u]) if(v!=fa&&ban[u]!=v) { if(col[v]) { cu=u,cv=v,ban[u]=v,ban[v]=u; continue; } col[v]=-col[u],dfs1(v,u); } } void dfs2(int u, int fa) { f[u]=col[u]; for(auto v:e[u]) if(v!=fa&&ban[u]!=v) dfs2(v,u),f[u]+=f[v],s[u]+=s[v]; } int main() { n=gi(),m=gi(); for(int i=1;i<=n;++i) e[i].clear(),col[i]=f[i]=ban[i]=s[i]=0; for(int i=1;i<=m;++i) { int u=gi(),v=gi(); e[u].push_back(v),e[v].push_back(u); } if(n&1) {puts("-1"); continue;} col[1]=1,dfs1(1,0); s[cu]=1,s[cv]=-1,dfs2(1,0); if(m==n-1) { if(f[1]) {puts("-1"); continue;} int ans=0; for(int i=1;i<=n;++i) ans+=abs(f[i]); printf("%d\n",ans); } else if(col[cu]==col[cv]) { if(f[1]&1) {puts("-1"); continue;} int ans=abs(f[1]>>1); col[cu]-=(f[1]>>1),col[cv]-=(f[1]>>1); dfs2(1,0); for(int i=1;i<=n;++i) ans+=abs(f[i]); printf("%d\n",ans); } else { if(f[1]) {puts("-1"); continue;} int ans=0; vector<int> v; for(int i=1;i<=n;++i) if(!s[i]) ans+=abs(f[i]); else v.push_back(s[i]*f[i]); sort(v.begin(),v.end()); const int mid=v[v.size()-1>>1]; for(auto x:v) ans+=abs(x-mid); printf("%d\n",ans); } }
a.cc: In function 'int main()': a.cc:40:38: error: continue statement not within a loop 40 | if(n&1) {puts("-1"); continue;} | ^~~~~~~~ a.cc:45:47: error: continue statement not within a loop 45 | if(f[1]) {puts("-1"); continue;} | ^~~~~~~~ a.cc:52:49: error: continue statement not within a loop 52 | if(f[1]&1) {puts("-1"); continue;} | ^~~~~~~~ a.cc:61:47: error: continue statement not within a loop 61 | if(f[1]) {puts("-1"); continue;} | ^~~~~~~~
s260715910
p04010
C++
#include<bits/stdc++.h> using namespace std; inline int gi() { char c=getchar(); int x=0; for(;c<'0'||c>'9';c=getchar()); for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0'; return x; } const int N=1e5+5; vector<int> e[N]; int col[N],f[N],ban[N],n,m,cu,cv; void dfs1(int u, int fa) { for(auto v:e[u]) if(v!=fa&&ban[u]!=v) { if(col[v]) { cu=u,cv=v,ban[u]=v,ban[v]=u; continue; } col[v]=-col[u],dfs1(v,u); } } void dfs2(int u, int fa) { f[u]=col[u]; for(auto v:e[u]) if(v!=fa&&ban[u]!=v) dfs2(v,u),f[u]+=f[v]; } int main() { n=gi(),m=gi(); for(int i=1;i<=n;++i) e[i].clear(),col[i]=f[i]=ban[i]=0; for(int i=1;i<=m;++i) { int u=gi(),v=gi(); e[u].push_back(v),e[v].push_back(u); } if(n&1) {puts("-1"); continue;} col[1]=1,dfs1(1,0),dfs2(1,0); if(m==n-1) { if(f[1]) {puts("-1"); continue;} int ans=0; for(int i=1;i<=n;++i) ans+=abs(f[i]); printf("%d\n",ans); } else { if(f[1]&1) {puts("-1"); continue;} int ans=abs(f[1]>>1); col[cu]-=(f[1]>>1),col[cv]-=(f[1]>>1); dfs2(1,0); for(int i=1;i<=n;++i) ans+=abs(f[i]); printf("%d\n",ans); } }
a.cc: In function 'int main()': a.cc:40:38: error: continue statement not within a loop 40 | if(n&1) {puts("-1"); continue;} | ^~~~~~~~ a.cc:44:47: error: continue statement not within a loop 44 | if(f[1]) {puts("-1"); continue;} | ^~~~~~~~ a.cc:51:49: error: continue statement not within a loop 51 | if(f[1]&1) {puts("-1"); continue;} | ^~~~~~~~
s821763803
p04010
C++
#include<cstdio> using namespace std; const int N=1e5+5; struct Link{int to,nxt;}l[N<<1]; int n,m,a[N],head[N],tot=1; int fa[N],edge,rt; inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9') f=ch=='-'?-1:f,ch=getchar(); while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar(); return s*f; } inline void add(int x,int y){ l[++tot].to=y;l[tot].nxt=head[x];head[x]=tot; } int find(int x){ if(fa[x]==x) return x; return fa[x]=find(fa[x]); } void dfs(int x,int fa,int opt){ a[x]=opt; for(int i=head[x];i;i=l[i].nxt){ int y=l[i].to; if(y==fa) continue; dfs(y,x);a[x]+=a[y]; } } int st[N],in[N],top; void get_roof(int x,int fa){ in[st[++top]=x]=1; for(int i=head[x];i;i=l[i].nxt){ int y=l[i].to; if(y==fa) continue; if(in[y]){ edge=i;rt=x; do{ }while() } else get_roof(y,x); } } int main(){ n=read(),m=read(); for(int i=1;i<=n;++i){ int x=read(),y=read(); add(x,y),add(y,x); } dfs(rt,0); if(n==m){ if() } else if(a[rt]) return puts("-1"),0; int res=0; for(int i=1;i<=n;++i) res+=abs(a[i]); }
a.cc: In function 'void dfs(int, int, int)': a.cc:25:20: error: too few arguments to function 'void dfs(int, int, int)' 25 | dfs(y,x);a[x]+=a[y]; | ~~~^~~~~ a.cc:20:6: note: declared here 20 | void dfs(int x,int fa,int opt){ | ^~~ a.cc: In function 'void get_roof(int, int)': a.cc:38:32: error: expected primary-expression before ')' token 38 | }while() | ^ a.cc:38:33: error: expected ';' before '}' token 38 | }while() | ^ | ; 39 | } | ~ a.cc: In function 'int main()': a.cc:49:12: error: too few arguments to function 'void dfs(int, int, int)' 49 | dfs(rt,0); | ~~~^~~~~~ a.cc:20:6: note: declared here 20 | void dfs(int x,int fa,int opt){ | ^~~ a.cc:51:20: error: expected primary-expression before ')' token 51 | if() | ^ a.cc:52:9: error: expected primary-expression before '}' token 52 | } | ^ a.cc:55:36: error: 'abs' was not declared in this scope 55 | for(int i=1;i<=n;++i) res+=abs(a[i]); | ^~~
s392630612
p04010
C++
#include<bits/stdc++.h> using namespace std; #define ll long long #define I int #define GG(x) if(x)printf("-1\n"),exit(0); const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);}
a.cc:6:49: error: ISO C++ forbids declaration of 'E' with no type [-fpermissive] 6 | const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);} | ^ a.cc: In function 'int E(int, int)': a.cc:6:86: warning: no return statement in function returning non-void [-Wreturn-type] 6 | const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);} | ^ a.cc: At global scope: a.cc:6:133: error: ISO C++ forbids declaration of 'D' with no type [-fpermissive] 6 | const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);} | ^ a.cc: In function 'int D(int, int)': a.cc:6:274: warning: no return statement in function returning non-void [-Wreturn-type] 6 | const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);} | ^ a.cc: At global scope: a.cc:6:275: error: ISO C++ forbids declaration of 'D2' with no type [-fpermissive] 6 | const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);} | ^~ a.cc: In function 'int D2(int, int)': a.cc:6:442: warning: no return statement in function returning non-void [-Wreturn-type] 6 | const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);} | ^ a.cc: At global scope: a.cc:6:443: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 6 | const I N=1e6+5;struct G{I o,r;}e[N];I h[N],w=1;E(I x,I y){e[w]=(G){y,h[x]};h[x]=w++;}I S[N],d[N],K[N],V[N],X,Y,L,T=0,Q[N],P;ll A=0;D(I u,I f){V[u]=((d[u]&1)?1:-1);P+=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(v^f)d[v]?(X=u,Y=v,L=abs(d[u]-d[v])+1):(d[v]=d[u]+1,D(v,u),0);}}D2(I u,I f){S[u]=V[u];for(I i=h[u];i;i=e[i].r){I v=e[i].o;if(!(v==f||(u==X&&v==Y)||(u==Y&&v==X)))D2(v,u),S[u]+=S[v],K[u]+=K[v];}K[u]?(Q[++T]=K[u]*S[u]):(A+=abs(S[u]));}main(){I n,m;scanf("%d%d",&n,&m);for(I i=1;i<=m;i++){I x,y;scanf("%d%d",&x,&y),E(x,y),E(y,x);}d[1]=1;D(1,1);if(m==n-1){GG(P)}else if(L&1){GG(P&1)A+=abs(P)/2,V[X]-=P/2,V[Y]-=P/2;}else {GG(P)K[X]++,K[Y]--;}D2(1,1);Q[++T]=0;sort(Q+1,Q+T+1);for(I i=1;i<=T;i++)A+=abs(Q[(T+1)/2]+Q[i]);printf("%lld\n",A);} | ^~~~
s779266336
p04010
C++
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define ll long long using namespace std; int h[100011]; int d[100011]; int can[100011]; vector<int>tab[100011]; ll ans=0; int maxHNode=0; int maxH=0; void dfs1(int now,int fa) { h[now]=0; int sz=tab[now].size(); int mx=0,lmx=0; for(int i=0;i<sz;++i) { int nex=tab[now][i]; if(nex==fa)continue; dfs1(nex,now); if(h[nex]>=mx) { lmx=mx; mx=h[nex]; }else if(h[nex]>=lmx) { lmx=h[nex]; } } h[now]=lmx+1; //cout<<now<<" "<<h[now]<<endl; if(h[now]>maxH) { maxH=h[now]; maxHNode=now; } } void dfs2(int now,int fa,int depth) { d[now]=depth; can[h[now]]+=(d[now]&1)?-1:1; ans+=d[now]*((h[now]&1)?1:-1); //cout<<now<<" "<<d[now]<<" "<<h[now]<<endl; int sz=tab[now].size(); for(int i=0;i<sz;++i) { int nex=tab[now][i]; if(nex==fa)continue; dfs2(nex,now,depth+1); } } int main() { int n,m; cin>>n>>m; if(m!=n-1) { cout<<-1<<endl; return 0; } for(int i=1;i<n;++i) { int a,b; cin>>a>>b; tab[a].push_back(b); tab[b].push_back(a); } dfs1(1,1); dfs2(maxHNode,maxHNode,0); for(int i=1;i<=n;++i) { //cout<<can[i]<<" "; if(can[i]!=0) { cout<<-1<<endl; return 0; } } //cout<<endl; cout<<ans<<endl; return 0; }
a.cc:11:1: error: 'vector' does not name a type 11 | vector<int>tab[100011]; | ^~~~~~ a.cc: In function 'void dfs1(int, int)': a.cc:18:16: error: 'tab' was not declared in this scope; did you mean 'tan'? 18 | int sz=tab[now].size(); | ^~~ | tan a.cc: In function 'void dfs2(int, int, int)': a.cc:48:16: error: 'tab' was not declared in this scope; did you mean 'tan'? 48 | int sz=tab[now].size(); | ^~~ | tan a.cc: In function 'int main()': a.cc:69:17: error: 'tab' was not declared in this scope; did you mean 'tan'? 69 | tab[a].push_back(b); | ^~~ | tan
s884865917
p04010
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int __SIZE = 1 << 18; char ibuf[__SIZE], *iS, *iT; #define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++) #define ri read_int() #define rl read_ll() #define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout) template<typename T> inline void read(T &x) { char ch, t = 0; x = 0; while(!isdigit(ch = ge)) t |= ch == '-'; while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge; x = t ? -x : x; } inline int read_int() { int x; return read(x), x; } inline ll read_ll() { ll x; return read(x), x; } template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; } const int MAXN = 100010; int n; int m; int tot; int fi[MAXN]; int to[MAXN << 1]; int ne[MAXN << 1]; inline void Link(int u, int v) { tot++; to[tot] = v; ne[tot] = fi[u]; fi[u] = tot; } int col[MAXN]; inline ll Dfs(int x, int la, int d) { ll res = 0; col[x] = d; for(int i = fi[x]; i; i = ne[i]) { int u = to[i]; if(u == la) continue; res += Dfs1(u, x, -d), col[x] += col[u]; } return res + abs(col[x]); } int main() { n = ri, m = ri; if(n & 1) return puts("-1"), 0; for(int i = 1; i <= m; i++) { int u = ri, v = ri; Link(u, v), Link(v, u); } if(m == n - 1) return cout << Dfs(1, 0, 1) << endl, 0; return 0; }
a.cc: In function 'll Dfs(int, int, int)': a.cc:52:24: error: 'Dfs1' was not declared in this scope; did you mean 'Dfs'? 52 | res += Dfs1(u, x, -d), col[x] += col[u]; | ^~~~ | Dfs
s787564154
p04010
C++
#include<bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned long long #define mp make_pair #define pb push_back #define pii pair<int,int> #define pll pair<LL,LL> #define x first #define y second #define pi acos(-1) #define sqr(x) ((x)*(x)) #define pdd pair<double,double> #define MEMS(x) memset(x,-1,sizeof(x)) #define MEM(x) memset(x,0,sizeof(x)) #define less Less #define EPS 1e-4 #define arg ARG #define cpdd const pdd #define rank Rank #define KK 500 #define N 100005 #define MXN 200005 vector<int> v[100005]; LL ans; int dep[100005]; int val[100005]; int a,b; int dfs(int x,int f){ dep[x]=dep[f]+1; int sum=0; for(auto it:v[x]){ if(it!=f){ if((it==a&&x==b)||(it==b&&x==a))continue; sum+=dfs(it,x); } } if(dep[x]&1)sum++; else sum--; sum+=val[x]; ans+=abs(sum); return sum; } int vis[100005]; vector<int> circle; vector<int> stk; int Find; void dfsc(int x,int f){ stk.pb(x); vis[x]=1; for(auto it:v[x]){ if(it!=f){ if(vis[it]){ while(stk.back()!=it){ circle.pb(stk.back()); stk.pop_back(); } circle.pb(stk.back()); Find=1; } else{ dfsc(it,x); } if(Find)return; } } if(stk.back()==x)stk.pop_back(); } int main(){ int n,m; scanf("%d %d",&n,&m); for(int i = 0;i<m;i++){ int x,y; scanf("%d %d",&x,&y); v[x].pb(y); v[y].pb(x); } if(m==n){ dfsc(1,0); for(auto it:circle) printf("%d ",it); printf("\n"); if(circle.size()&1){ a=cirlce[0],b=cirlce[1]; int x=dfs(1,0); if(x&1){ printf("-1\n"); } else{ val[circle[0]]=-x/2; val[circle[1]]=-x/2; } printf("%d\n",dfs(1,0)); } else{ assert(0); } return 0; } if(dfs(1,0)){ printf("-1\n"); } else printf("%lld\n",ans); }
a.cc: In function 'int main()': a.cc:84:15: error: 'cirlce' was not declared in this scope; did you mean 'circle'? 84 | a=cirlce[0],b=cirlce[1]; | ^~~~~~ | circle
s897502590
p04010
C++
#include <bits/stdc++.h> const int N = 1e5 + 54; int n, m; namespace Tree { struct node { int u, v; } edge[N << 1]; int head[N], v[N], col[N], cnt; long long sum, ans; inline void add(int x, int y) { edge[cnt].u = head[x], edge[cnt].v = y, head[x] = cnt++; } void dfs(int x, int fa) { int i; for (i = head[x]; ~i; i = edge[i].u) { int y = edge[i].v; if (y == fa) continue; col[y] = 1 - col[x], dfs(y, x); } } void solve(int x, int fa) { int i; for (i = head[x]; ~i; i = edge[i].u) { int y = edge[i].v; if (y == fa) continue; solve(y, x); v[x] += v[y]; } } void SOLVE() { int x, y, i; memset(head, -1, sizeof head); for (i = 1; i <= m; ++i) scanf("%d%d", &x, &y), add(x, y), add(y, x); col[1] = 1, dfs(1, 0); for (i = 1; i <= n; ++i) { if (col[i]) v[i] = 1; else v[i] = -1; sum += v[i]; } if (sum) { puts("-1"); return; } solve(1, 0); for (i = 1; i <= n; ++i) ans += abs(v[i]); printf("%lld\n", ans); } } namespace BRT { struct Edge { int id, x, y; } E; struct node { int u, v; } edge[N << 1]; int head[N], v[N], col[N], cnt, tot, p[N], vis[N], f[N]; long long sum, ans; inline void add(int x, int y) { edge[cnt].u = head[x], edge[cnt].v = y, head[x] = cnt++; } void dfs(int x, int fa) { int i; vis[x] = 1; for (i = head[x]; ~i; i = edge[i].u) { int y = edge[i].v; if (y == fa) continue; if (vis[y]) E.id = i, E.x = x, E.y = y; else col[y] = 1 - col[x], dfs(y, x); } } void solve(int x, int fa) { int i; for (i = head[x]; ~i; i = edge[i].u) { int y = edge[i].v; if (y == fa || i == E.id || (i ^ 1) == E.id) continue; solve(y, x), v[x] += v[y], f[x] += f[y]; } } void SOLVE() { memset(head, -1, sizeof head); int x, y, i; for (i = 1; i <= m; ++i) scanf("%d%d", &x, &y), add(x, y), add(y, x); col[1] = 1, dfs(1, 0); for (i = 1; i <= n; ++i) { if (col[i]) v[i] = 1; else v[i] = -1; sum += v[i]; } if (col[E.x] == col[E.y]) { if (abs(sum) & 1) { puts("-1"); return; } v[E.x] -= sum / 2, v[E.y] -= sum / 2, ans += abs(sum / 2); } else { if (sum) { puts("-1"); return; } f[E.x] = 1, f[E.y] = -1; } solve(1, 0); if (col[E.x] == col[E.y]) { for (i = 1; i <= n; ++i) ans += abs(v[i]); printf("%lld\n", ans); return; } for (i = 1; i <= n; ++i) if (f[i] == 0) ans += abs(v[i]); else p[++tot] = -v[i]; p[++tot] = 0; std::sort(p + 1, p + tot + 1); ll mid = p[(tot + 1) >> 1]; for (i = 1; i <= tot; ++i) ans += abs(v[i] - mid); printf("%lld\n", ans); } } int main() { scanf("%d%d", &n, &m); if (m == n - 1) Tree::SOLVE(); else BRT::SOLVE(); }
a.cc: In function 'void BRT::SOLVE()': a.cc:104:17: error: 'll' was not declared in this scope 104 | ll mid = p[(tot + 1) >> 1]; | ^~ a.cc:105:62: error: 'mid' was not declared in this scope 105 | for (i = 1; i <= tot; ++i) ans += abs(v[i] - mid); | ^~~
s009361291
p04010
C++
//minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i) #define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i) #define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v) template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;} template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;} using namespace std; const int N=1e5+5; struct eg{int v,nx;}e[N<<1];int head[N],tot; inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;} int d[N],n,m,res; void dfs(int u,int fa){ go(u)if(v!=fa){ dfs(v,u); if(!d[v])d[u]^=1,d[v]^=1,++res; } } void solve1(){ for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u); dfs(1,0); res=(d[1]?res:-1); printf("%d\n",res); } int main(){ scanf("%d%d",&n,&m); assert(m==n-1); return m==n-1?solve1():solve2(),0; }
a.cc:12:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 12 | inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;} | ^ a.cc:12:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 12 | inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;} | ^ a.cc: In function 'void solve1()': a.cc:21:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 21 | for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u); | ^ a.cc:21:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 21 | for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u); | ^ a.cc:21:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 21 | for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u); | ^ a.cc: In function 'int main()': a.cc:29:32: error: 'solve2' was not declared in this scope; did you mean 'solve1'? 29 | return m==n-1?solve1():solve2(),0; | ^~~~~~ | solve1
s965225195
p04010
C++
//minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i) #define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i) #define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v) template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;} template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;} using namespace std; const int N=1e5+5; struct eg{int v,nx;}e[N<<1];int head[N],tot; inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;} int d[N],n,m,res; void dfs(int u,int fa){ go(u)if(v!=fa){ dfs(v,u); if(!d[v])d[u]^=1,++res; } } void solve1(){ for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v); dfs(1,0); res=(!d[1]?-1:res); printf("%d\n",res); } int main(){ scanf("%d%d",&n,&m); assert(m==n-1); return m==n-1?solve1():solve2(),0; }
a.cc:12:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 12 | inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;} | ^ a.cc:12:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 12 | inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;} | ^ a.cc: In function 'void solve1()': a.cc:21:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 21 | for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v); | ^ a.cc:21:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 21 | for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v); | ^ a.cc:21:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 21 | for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v); | ^ a.cc: In function 'int main()': a.cc:29:32: error: 'solve2' was not declared in this scope; did you mean 'solve1'? 29 | return m==n-1?solve1():solve2(),0; | ^~~~~~ | solve1
s798319673
p04010
C++
#include <algorithm> #include <iostream> #include <cstring> #include <vector> using namespace std; const int MAX_N = 1e5 + 5; int n, m; vector <int> G[MAX_N]; bool dfsTree (int v = 0, int p = 0) { int size = 1; } int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { int v, u; cin >> v >> u; v--, u--; G[v].push_back(u); G[u].push_back(v); } if (n & 1) { cout << "-1\n"; } assert(false); if (n - 1 == m) { if (dfsTree()) cout << (n >> 1) << "\n"; else cout << "-1\n"; } return 0; }
a.cc: In function 'bool dfsTree(int, int)': a.cc:13:1: warning: no return statement in function returning non-void [-Wreturn-type] 13 | } | ^ a.cc: In function 'int main()': a.cc:30:9: error: 'assert' was not declared in this scope 30 | assert(false); | ^~~~~~ 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;
s769518547
p04010
C++
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <map> #include <set> #include <stack> #include <queue> #define rep(i,l,r) for(int i=(l);i<=(r);++i) #define per(i,r,l) for(int i=(r);i>=(l);--i) #define pb push_back using namespace std; const int maxn=1e5+10; int f[maxn],vis[maxn],fa[maxn],d[maxn],u,v,x,y,a[maxn],cnt,n,m; vector<int> G[maxn];ll ans; void dfs(int u){ f[u]=1;vis[u]=1; for(int v:G[u]) if(v^fa[u]){ if(vis[v]){x=u,y=v;continue;} fa[v]=u;d[v]=d[u]+1;dfs(v); f[u]-=f[v]; } } int lca(int u,int v){ if(d[u]<d[v]) swap(u,v); while(d[u]^d[v]) u=fa[u]; while(u^v) u=fa[u],v=fa[v]; return u; } int main(){ scanf("%d%d",&n,&m); rep(i,1,m) scanf("%d%d",&u,&v),G[u].pb(v),G[v].pb(u); dfs(1); if(m==n-1){ if(f[1]) return puts("-1"),0; rep(i,1,n) ans+=abs(f[i]); } else if(!((d[x]^d[y])&1)){ if(f[1]&1) return puts("-1"),0; int fxk=-(f[1]>>1);ans+=abs(fxk); for(int u=x;u;u=fa[u]) f[u]+=fxk; for(int u=y;u;u=fa[u]) f[u]+=fxk; rep(i,1,n) ans+=abs(f[i]); } else{ if(f[1]) return puts("-1"),0; int t=lca(x,y); for(int u=x;u^t;u=fa[u]) a[++cnt]=f[u],vis[u]=0; for(int u=y;u^t;u=fa[u]) a[++cnt]=-f[u],vis[u]=0;a[++cnt]=0; sort(a+1,a+cnt+1);int fxk=a[cnt+1>>1]; rep(i,1,n) if(vis[i]) ans+=abs(f[i]); rep(i,1,cnt) ans+=abs(a[i]-fxk); } printf("%lld\n",ans); return 0; }
a.cc:17:21: error: 'll' does not name a type 17 | vector<int> G[maxn];ll ans; | ^~ a.cc: In function 'int main()': a.cc:38:28: error: 'ans' was not declared in this scope; did you mean 'abs'? 38 | rep(i,1,n) ans+=abs(f[i]); | ^~~ | abs a.cc:42:36: error: 'ans' was not declared in this scope; did you mean 'abs'? 42 | int fxk=-(f[1]>>1);ans+=abs(fxk); | ^~~ | abs a.cc:53:39: error: 'ans' was not declared in this scope; did you mean 'abs'? 53 | rep(i,1,n) if(vis[i]) ans+=abs(f[i]); | ^~~ | abs a.cc:54:30: error: 'ans' was not declared in this scope; did you mean 'abs'? 54 | rep(i,1,cnt) ans+=abs(a[i]-fxk); | ^~~ | abs a.cc:56:25: error: 'ans' was not declared in this scope; did you mean 'abs'? 56 | printf("%lld\n",ans); | ^~~ | abs
s376274319
p04010
C++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } struct node { int to,next; }E[MAXN * 2]; int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; bool vis[MAXN]; int c[MAXN],tot; int sta[MAXN],top,num[MAXN]; void add(int u,int v) { E[++sumE].to = v; E[sumE].next = head[u]; head[u] = sumE; } void dfs(int u) { dp[u][0] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(v != fa[u]) { fa[v] = u; dfs(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t;dp[u][1] -= t; } void find_circle(int u) { dep[u] = dep[fa[u]] + 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { fa[v] = u; find_circle(v); } else if(dep[v] < dep[u]) { st = u;ed = v; } } } void Calc(int u) { dp[u][0] = 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { Calc(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t; dp[u][1] -= t; } void Solve() { read(N);read(M); int a,b; for(int i = 1 ; i <= M ; ++i) { read(a);read(b); add(a,b);add(b,a); } if(N & 1) {puts("-1");return;} if(M == N - 1) { dfs(1); if(dp[1][0] || dp[1][1]) {puts("-1");return;} out(ans);enter; } else { find_circle(1); int p = st; while(1) { c[++tot] = p; if(p == ed) break; p = fa[p]; } memset(vis,0,sizeof(vis)); for(int i = 1 ; i <= tot ; ++i) vis[c[i]] = 1; for(int i = 1 ; i <= tot ; ++i) { Calc(c[i]); } top = 0; for(int i = 1 ; i <= tot ; ++i) { int u = c[i]; pre[i] = pre[i - 1]; if(dp[u][0] || dp[u][1]) { pre[i] += (i - 1) * (dp[u][0]+dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) { int t = k ^ ((i - 1) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { pre[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) { sta[++top] = i - 1;num[top] = t; } } } if(top) prez[i][num[top]] = top; } top = 0; for(int i = tot ; i >= 1 ; --i) { int u = c[i]; suf[i] = suf[i + 1]; if(dp[u][0] || dp[u][1]) { suf[i] += (tot - i) * (dp[u][0] + dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) {#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } struct node { int to,next; }E[MAXN * 2]; int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; bool vis[MAXN]; int c[MAXN],tot; int sta[MAXN],top,num[MAXN]; void add(int u,int v) { E[++sumE].to = v; E[sumE].next = head[u]; head[u] = sumE; } void dfs(int u) { dp[u][0] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(v != fa[u]) { fa[v] = u; dfs(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t;dp[u][1] -= t; } void find_circle(int u) { dep[u] = dep[fa[u]] + 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { fa[v] = u; find_circle(v); } else if(dep[v] < dep[u]) { st = u;ed = v; } } } void Calc(int u) { dp[u][0] = 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { Calc(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t; dp[u][1] -= t; } void Solve() { read(N);read(M); int a,b; for(int i = 1 ; i <= M ; ++i) { read(a);read(b); add(a,b);add(b,a); } if(N & 1) {puts("-1");return;} if(M == N - 1) { dfs(1); if(dp[1][0] || dp[1][1]) {puts("-1");return;} out(ans);enter; } else { find_circle(1); int p = st; while(1) { c[++tot] = p; if(p == ed) break; p = fa[p]; } memset(vis,0,sizeof(vis)); for(int i = 1 ; i <= tot ; ++i) vis[c[i]] = 1; for(int i = 1 ; i <= tot ; ++i) { Calc(c[i]); } top = 0; for(int i = 1 ; i <= tot ; ++i) { int u = c[i]; pre[i] = pre[i - 1]; if(dp[u][0] || dp[u][1]) { pre[i] += (i - 1) * (dp[u][0]+dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) { int t = k ^ ((i - 1) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { pre[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) { sta[++top] = i - 1;num[top] = t; } } } if(top) prez[i][num[top]] = top; } top = 0; for(int i = tot ; i >= 1 ; --i) { int u = c[i]; suf[i] = suf[i + 1]; if(dp[u][0] || dp[u][1]) { suf[i] += (tot - i) * (dp[u][0] + dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) { int t = k ^ ((tot - i) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { suf[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) {sta[++top] = tot - i;num[top] = t;} } } if(top) sufz[i][num[top]] = top; } if(tot % 2 == 0) { int64 res = 1e18; for(int i = 1 ; i <= tot ; ++i) { if(prez[i][0] == sufz[i + 1][0] && prez[i][1] == sufz[i + 1][1]) { res = min(res,pre[i] + suf[i + 1] + prez[i][0] + prez[i][1]); } } if(res >= 1e18) { puts("-1"); } else {out(ans + res);enter;} } else { int64 a = 1; for(int64 i = 1 ; i <= 1e18 ; ++i) a <<= 1LL; out(a);enter; } } }#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } struct node { int to,next; }E[MAXN * 2]; int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; bool vis[MAXN]; int c[MAXN],tot; int sta[MAXN],top,num[MAXN]; void add(int u,int v) { E[++sumE].to = v; E[sumE].next = head[u]; head[u] = sumE; } void dfs(int u) { dp[u][0] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(v != fa[u]) { fa[v] = u; dfs(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t;dp[u][1] -= t; } void find_circle(int u) { dep[u] = dep[fa[u]] + 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { fa[v] = u; find_circle(v); } else if(dep[v] < dep[u]) { st = u;ed = v; } } } void Calc(int u) { dp[u][0] = 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { Calc(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t; dp[u][1] -= t; } void Solve() { read(N);read(M); int a,b; for(int i = 1 ; i <= M ; ++i) { read(a);read(b); add(a,b);add(b,a); } if(N & 1) {puts("-1");return;} if(M == N - 1) { dfs(1); if(dp[1][0] || dp[1][1]) {puts("-1");return;} out(ans);enter; } else { find_circle(1); int p = st; while(1) { c[++tot] = p; if(p == ed) break; p = fa[p]; } memset(vis,0,sizeof(vis)); for(int i = 1 ; i <= tot ; ++i) vis[c[i]] = 1; for(int i = 1 ; i <= tot ; ++i) { Calc(c[i]); } top = 0; for(int i = 1 ; i <= tot ; ++i) { int u = c[i]; pre[i] = pre[i - 1]; if(dp[u][0] || dp[u][1]) { pre[i] += (i - 1) * (dp[u][0]+dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) { int t = k ^ ((i - 1) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { pre[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) { sta[++top] = i - 1;num[top] = t; } } } if(top) prez[i][num[top]] = top; } top = 0; for(int i = tot ; i >= 1 ; --i) { int u = c[i]; suf[i] = suf[i + 1]; if(dp[u][0] || dp[u][1]) { suf[i] += (tot - i) * (dp[u][0] + dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) { int t = k ^ ((tot - i) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { suf[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) {sta[++top] = tot - i;num[top] = t;} } } if(top) sufz[i][num[top]] = top; } if(tot % 2 == 0) { int64 res = 1e18; for(int i = 1 ; i <= tot ; ++i) { if(prez[i][0] == sufz[i + 1][0] && prez[i][1] == sufz[i + 1][1]) { res = min(res,pre[i] + suf[i + 1] + prez[i][0] + prez[i][1]); } } if(res >= 1e18) { puts("-1"); } else {out(ans + res);enter;} } else { int64 a = 1; for(int64 i = 1 ; i <= 1e18 ; ++i) a <<= 1LL; out(a);enter; } } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; } int t = k ^ ((tot - i) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { suf[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) {sta[++top] = tot - i;num[top] = t;} } } if(top) sufz[i][num[top]] = top; } if(tot % 2 == 0) { int64 res = 1e18; for(int i = 1 ; i <= tot ; ++i) { if(prez[i][0] == sufz[i + 1][0] && prez[i][1] == sufz[i + 1][1]) { res = min(res,pre[i] + suf[i + 1] + prez[i][0] + prez[i][1]); } } if(res >= 1e18) { puts("-1"); } else {out(ans + res);enter;} } else { int64 a = 1; for(int64 i = 1 ; i <= 1e18 ; ++i) a <<= 1LL; out(a);enter; } } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
a.cc:150:44: error: stray '#' in program 150 | for(int k = 0 ; k <= 1 ; ++k) {#include <bits/stdc++.h> | ^ a.cc:330:2: error: stray '#' in program 330 | }#include <bits/stdc++.h> | ^ a.cc: In function 'void Solve()': a.cc:150:45: error: 'include' was not declared in this scope 150 | for(int k = 0 ; k <= 1 ; ++k) {#include <bits/stdc++.h> | ^~~~~~~ a.cc:150:54: error: 'bits' was not declared in this scope 150 | for(int k = 0 ; k <= 1 ; ++k) {#include <bits/stdc++.h> | ^~~~ a.cc:150:59: error: 'stdc' was not declared in this scope; did you mean 'std'? 150 | for(int k = 0 ; k <= 1 ; ++k) {#include <bits/stdc++.h> | ^~~~ | std a.cc:161:1: error: expected primary-expression before 'using' 161 | using namespace std; | ^~~~~ a.cc:165:1: error: a template declaration cannot appear at block scope 165 | template<class T> | ^~~~~~~~ a.cc:194:23: error: a function-definition is not allowed here before '{' token 194 | void add(int u,int v) { | ^ a.cc:199:17: error: a function-definition is not allowed here before '{' token 199 | void dfs(int u) { | ^ a.cc:214:25: error: a function-definition is not allowed here before '{' token 214 | void find_circle(int u) { | ^ a.cc:228:18: error: a function-definition is not allowed here before '{' token 228 | void Calc(int u) { | ^ a.cc:244:14: error: a function-definition is not allowed here before '{' token 244 | void Solve() { | ^ a.cc:341:1: error: expected primary-expression before 'using' 341 | using namespace std; | ^~~~~ a.cc:345:1: error: a template declaration cannot appear at block scope 345 | template<class T> | ^~~~~~~~ a.cc:366:8: error: redefinition of 'struct Solve()::node' 366 | struct node { | ^~~~ a.cc:186:8: note: previous definition of 'struct Solve()::node' 186 | struct node { | ^~~~ a.cc:368:2: error: conflicting declaration 'int E [200010]' 368 | }E[MAXN * 2]; | ^ a.cc:188:2: note: previous declaration as 'Solve()::node E [200010]' 188 | }E[MAXN * 2]; | ^ a.cc:369:5: error: redeclaration of 'int N' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^ a.cc:189:5: note: 'int N' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^ a.cc:369:7: error: redeclaration of 'int head [100005]' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~~~ a.cc:189:7: note: 'int head [100005]' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~~~ a.cc:369:18: error: redeclaration of 'int sumE' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~~~ a.cc:189:18: note: 'int sumE' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~~~ a.cc:369:23: error: redeclaration of 'int M' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^ a.cc:189:23: note: 'int M' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^ a.cc:369:25: error: redeclaration of 'int fa [100005]' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~ a.cc:189:25: note: 'int fa [100005]' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~ a.cc:369:34: error: redeclaration of 'int dep [100005]' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~~ a.cc:189:34: note: 'int dep [100005]' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~~ a.cc:369:44: error: redeclaration of 'int st' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~ a.cc:189:44: note: 'int st' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~ a.cc:369:47: error: redeclaration of 'int ed' 369 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~ a.cc:189:47: note: 'int ed' previously declared here 189 | int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; | ^~ a.cc:370:7: error: redeclaration of 'int64 dp [100005][2]' 370 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~ a.cc:190:7: note: 'int64 dp [100005][2]' previously declared here 190 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~ a.cc:370:19: error: redeclaration of 'int64 ans' 370 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~ a.cc:190:19: note: 'int64 ans' previously declared here 190 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~ a.cc:370:23: error: redeclaration of 'int64 pre [100005]' 370 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~ a.cc:190:23: note: 'int64 pre [100005]' previously declared here 190 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~ a.cc:370:33: error: redeclaration of 'int64 suf [100005]' 370 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~ a.cc:190:33: note: 'int64 suf [100005]' previously declared here 190 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~ a.cc:370:43: error: redeclaration of 'int64 prez [100005][2]' 370 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~~ a.cc:190:43: note: 'int64 prez [100005][2]' previously declared here 190 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~~ a.cc:370:57: error: redeclaration of 'int64 sufz [100005][2]' 370 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~~ a.cc:190:57: note: 'int64 sufz [100005][2]' previously declared here 190 | int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; | ^~~~ a.cc:371:6: error: redeclaration of 'bool vis [100005]' 371 | bool vis[MAXN]; | ^~~ a.cc:191:6: note: 'bool vis [100005]' previously declared here 191 | bool vis[MAXN]; | ^~~ a.cc:372:5: error: redeclaration of 'int c [100005]' 372 | int c[MAXN],tot; | ^ a.cc:192:5: note: 'int c [100005]' previously declared here 192 | int c[MAXN],tot; | ^ a.cc:372:13: error: redeclaration of 'int tot' 372 | int c[MAXN],tot; | ^~~ a.cc:192:13: note: 'int tot' previously declared here 192 | int c[MAXN],tot; | ^~~ a.cc:373:5: error: redeclaration of 'int sta [100005]' 373 | int sta[MAXN],top,num[MAXN]; | ^~~ a.cc:193:5: note: 'int sta [100005]' previously declared here 193 | int sta[MAXN],top,num[MAXN]; | ^~~ a.cc:373:15: error: redeclaration of 'int top' 373 | int sta[MAXN],top,num[MAXN]; | ^~~ a.cc:193:15: note: 'int top' previously declared here 193 | int sta[MAXN],top,num[MAXN]; | ^~~ a.cc:373:19: error: redeclaration of 'int num [100005]' 373 | int sta[MAXN],top,num[MAXN]; | ^~~ a.cc:193:19: note: 'int num [100005]' previously declared here 193 | int sta[MAXN],top,num[MAXN]; | ^~~ a.cc:374:23: error: a function-definition is not allowed here before '{' token 374 | void add(int u,int v) { | ^ a.cc:379:17: error: a function-definition is not allowed here before '{' token 379 | void dfs(int u) { | ^ a.cc:394:25: error: a function-definition is not allowed here before '{' token 394 | void find_circle(int u) { | ^ a.cc:408:18: error: a function-definition is not allowed here before '{' token 408 | void Calc(int u) { | ^ a.cc:424:14: error: a function-definition is not allowed here before '{' token 424 | void Solve() { | ^ a.cc:512:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 512 | int main() { | ^~ a.cc:512:9: note: remove parentheses to default-initialize a variable 512 | int main() { | ^~ | -- a.cc:512:9: note: or replace parentheses with braces to value-initialize a variable a.cc:512:12: error: a function-definition is not allowed here before '{' token 512 | int main() { | ^ a.cc:521:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 521 | int main() { | ^~ a.cc:521:9: note: remove parentheses to default-initialize a variable 521 | int main() { | ^~ | -- a.cc:521:9: note: or replace parentheses with braces to value-initialize a variable a.cc:521:12: error: a function-definition is not allowed here before '{' token 521 | int main() { | ^
s516010929
p04010
C++
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } struct node { int to,next; }E[MAXN * 2]; int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed; int64 dp[MAXN][2],ans,pre[MAXN],suf[MAXN],prez[MAXN][2],sufz[MAXN][2]; bool vis[MAXN]; int c[MAXN],tot; int sta[MAXN],top,num[MAXN]; void add(int u,int v) { E[++sumE].to = v; E[sumE].next = head[u]; head[u] = sumE; } void dfs(int u) { dp[u][0] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(v != fa[u]) { fa[v] = u; dfs(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t;dp[u][1] -= t; } void find_circle(int u) { dep[u] = dep[fa[u]] + 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { fa[v] = u; find_circle(v); } else if(dep[v] < dep[u]) { st = u;ed = v; } } } void Calc(int u) { dp[u][0] = 1; vis[u] = 1; for(int i = head[u] ; i ; i = E[i].next) { int v = E[i].to; if(!vis[v]) { Calc(v); ans += dp[v][0] + dp[v][1]; dp[u][0] += dp[v][1]; dp[u][1] += dp[v][0]; } } int t = min(dp[u][0],dp[u][1]); dp[u][0] -= t; dp[u][1] -= t; } void Solve() { read(N);read(M); int a,b; for(int i = 1 ; i <= M ; ++i) { read(a);read(b); add(a,b);add(b,a); } if(N & 1) {puts("-1");return;} if(M == N - 1) { dfs(1); if(dp[1][0] || dp[1][1]) {puts("-1");return;} out(ans);enter; } else { find_circle(1); int p = st; while(1) { c[++tot] = p; if(p == ed) break; p = fa[p]; } memset(vis,0,sizeof(vis)); for(int i = 1 ; i <= tot ; ++i) vis[c[i]] = 1; for(int i = 1 ; i <= tot ; ++i) { Calc(c[i]); } top = 0; for(int i = 1 ; i <= tot ; ++i) { int u = c[i]; pre[i] = pre[i - 1]; if(dp[u][0] || dp[u][1]) { pre[i] += (i - 1) * (dp[u][0]+dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) { int t = k ^ ((i - 1) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { pre[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) { sta[++top] = i - 1;num[top] = t; } } } if(top) prez[i][num[top]] = top; } top = 0; for(int i = tot ; i >= 1 ; --i) { int u = c[i]; suf[i] = suf[i + 1]; if(dp[u][0] || dp[u][1]) { suf[i] += (tot - i) * (dp[u][0] + dp[u][1]); } for(int k = 0 ; k <= 1 ; ++k) { int t = k ^ ((tot - i) & 1); int cnt = dp[u][k]; while(cnt && top && num[top] == t ^ 1) { suf[i] -= sta[top] * 2; --top;--cnt; } if(cnt) { for(int j = 1 ; j <= cnt ; ++j) {sta[++top] = tot - i;num[top] = t;} } } if(top) sufz[i][num[top]] = top; } if(tot % 2 == 0) { int64 res = 1e18; for(int i = 1 ; i <= tot ; ++i) { if(prez[i][0] == sufz[i + 1][0] && prez[i][1] == sufz[i + 1][1]) { res = min(res,pre[i] + suf[i + 1] + prez[i][0] + prez[i][1]); } } if(res >= 1e18) { puts("-1"); } else {out(ans + res);enter;} } else { int64 a = 1; for(int64 i = 1 ; i <= 1e18LL ; ++i) a <<= 1LL; out(a);enter; } } } int main() { #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); return 0; }
a.cc: In function 'void Solve()': a.cc:177:36: error: unable to find numeric literal operator 'operator""LL' 177 | for(int64 i = 1 ; i <= 1e18LL ; ++i) a <<= 1LL; | ^~~~~~
s852257402
p04010
C++
#include<cstdio> #include<algorithm> #include<cmath> #include<vector> #define fo(i,a,b) for(i=a;i<=b;i++) using namespace std; typedef long long ll; const int maxn=100000+10; int h[maxn],go[maxn*2],nxt[maxn*2],fa[maxn],co[maxn],kk[maxn],bb[maxn],sta[maxn]; vector<int>G[maxn]; bool bz[maxn]; int i,j,k,l,t,n,m,u,v,a,b,x,tot,top,num; ll ans; bool czy,gjx; void add(int x,int y){ go[++tot]=y; nxt[tot]=h[x]; h[x]=tot; } int getfa(int x){ if (!fa[x]) return x; int t=getfa(fa[x]); co[x]=co[x]^co[fa[x]]; return fa[x]=t; } void travel(int x,int y){ bz[x]=1; int t=h[x]; for(int i=0;i<(int)G[x].size();i++){ go[t]=xx; if (go[t]!=y){ if (bz[go[t]]){ u=x;v=go[t]; if (co[u]==co[v]) gjx=1; } else{ co[go[t]]=co[x]^1; travel(go[t],x); } } t=nxt[t]; } } void dfs(int x,int y){ int t=h[x]; for(int i=0;i<(int)G[x].size();i++){ go[t]=xx; if (go[t]!=y&&!(x==u&&go[t]==v||x==v&&go[t]==u)){ dfs(go[t],x); kk[x]+=kk[go[t]]; bb[x]+=bb[go[t]]; } t=nxt[t]; } } int main(){ scanf("%d%d",&n,&m); fo(i,1,m){ scanf("%d%d",&j,&k); G[j].push_back(k); G[k].push_back(j); /*a=getfa(j);b=getfa(k); if (a!=b){ add(j,k);add(k,j); fa[a]=b; co[a]=co[j]^co[k]^1; } else{ u=j;v=k; if (co[j]==co[k]) gjx=1; }*/ } //fo(i,1,n) getfa(i); /*if (!co[1]) fo(i,1,n) co[i]^=1;*/ co[1]=1; travel(1,0); fo(i,1,n) if (co[i]) bb[i]=1;else bb[i]=-1; fo(i,1,n) num+=bb[i]; if (m==n-1){ if (num){ printf("-1\n"); return 0; } } else{ if (gjx){ if (num%2==1){ printf("-1\n"); return 0; } bb[u]-=num/2;bb[v]-=num/2; ans+=(ll)abs(num/2); } else{ if (num){ printf("-1\n"); return 0; } kk[u]=1;kk[v]=-1; } } dfs(1,0); fo(i,1,n) if (!kk[i]) ans+=(ll)abs(bb[i]); else{ if (kk[i]) bb[i]=-bb[i]; sta[++top]=bb[i]; } sta[++top]=0; sort(sta+1,sta+top+1); x=sta[(top+1)/2]; fo(i,1,top) ans+=(ll)abs(sta[i]-x); printf("%lld\n",ans); }
a.cc: In function 'void travel(int, int)': a.cc:30:15: error: 'xx' was not declared in this scope; did you mean 'x'? 30 | go[t]=xx; | ^~ | x a.cc: In function 'void dfs(int, int)': a.cc:47:15: error: 'xx' was not declared in this scope; did you mean 'x'? 47 | go[t]=xx; | ^~ | x
s283869115
p04010
C++
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #define DCSB {printf("-1");exit(0);} using namespace std; vector<int>G[100010]; struct edge{ int v,next; }a[500001]; int n,m,u,v,ans=0,els,huanu,huanv,tot=0,q[500001],head[500001],fa[500001],dep[500001],f[500001]; void add(int u,int v){ a[++tot].v=v; a[tot].next=head[u]; head[u]=tot; } void dfs(int u,int ff,int dpt){ dep[u]=dpt; fa[u]=ff; f[u]=(dpt%2)?1:-1; for(int i=0;i<(int)G[u].size();i++){ int v=G[u][i]; if(v!=ff){ if(dep[v]){ huanu=u; huanv=v; continue; } dfs(v,u,dpt+1); f[u]+=f[v]; } } } void gao_tree(){ if(f[1]!=0)DCSB for(int i=1;i<=n;i++)ans+=abs(f[i]); printf("%d",ans); } void gao_jihuan(){ if(f[1]%2!=0)DCSB els=-f[1]/2; ans=abs(els); for(;huanu;huanu=fa[huanu])f[huanu]+=els; for(;huanv;huanv=fa[huanv])f[huanv]+=els; for(int i=1;i<=n;i++)ans+=abs(f[i]); printf("%d",ans); } void gao_ouhuan(){ int top,mid; top=0; if(f[1])DCSB for(;huanv!=huanu;huanv=fa[huanv]){ q[++top]=f[huanv]; dep[huanv]=0; } sort(q+1,q+top+1); mid=q[(top+1)/2]; ans=abs(mid); for(int i=1;i<=n;i++)if(dep[i])ans+=abs(f[i]); for(int i=1;i<=top;i++)ans+=abs(q[i]-mid); printf("%d",ans); } int main(){ memset(head,-1,sizeof(head)); scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ scanf("%d%d",&u,&v); G[u].push_back(v); G[v].push_back(u); } dfs(1,0,1); if(m==n-1)gao_tree(); else if((dep[huanv]-dep[huanu])%2==0)gao_jihuan(); else gao_ouhuan(); return 0; }
a.cc:8:1: error: 'vector' does not name a type 8 | vector<int>G[100010]; | ^~~~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:22:24: error: 'G' was not declared in this scope 22 | for(int i=0;i<(int)G[u].size();i++){ | ^ a.cc: In function 'int main()': a.cc:69:9: error: 'G' was not declared in this scope 69 | G[u].push_back(v); | ^
s084995274
p04010
C++
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN=100005; int N,M; vector<int> adj[MAXN]; int dep[MAXN],sum[MAXN],k[MAXN]; bool vis[MAXN]; int cU,cV,clen; vector<int> num; void dfs(int u,int fa=0) { vis[u]=true; for(auto v:adj[u]) { if(v==fa) continue; if(vis[v]) { cU=u; cV=v; clen=dep[u]-dep[v]+1; continue; } dep[v]=dep[u]+1; dfs(v,u); } } void Calc(int u,int fa=0) { vis[u]=true; for(auto v:adj[u]) { if(v==fa||vis[v]) continue; Calc(v,u); sum[u]+=sum[v]; k[u]+=k[v]; } } int main() { scanf("%d%d",&N,&M); for(int i=1;i<=M;i++) { int a,b; scanf("%d%d",&a,&b); adj[a].push_back(b); adj[b].push_back(a); } dfs(1); int val=0; long long ans=0; for(int i=1;i<=N;i++) { sum[i]=(dep[i]&1)?-1:1; val+=sum[i]; } if(M==N-1) { if(val!=0) { puts("-1"); return 0; } } else { if(clen&1) { if(val&1) { puts("-1"); return 0; } else { ans+=(abs(val)/2); sum[cU]-=val/2; sum[cV]-=val/2; } } else { if(val!=0) { puts("-1"); return 0; } else { k[cU]=1; k[cU]=-1; } } } memset(vis,0,sizeof vis); Calc(1); for(int i=1;i<=N;i++) { if(k[i]==0) ans+=abs(sum[i]); else { if(k[i]==1) sum[i]=-sum[i]; num.push_back(sum[i]); } } num.push_back(0); sort(num.begin(),num.end()); int x=num[num.size()/2]; for(auto s:num) ans+=1LL*abs(s-x); printf("%lld\n",ans); return 0; }
a.cc:8:1: error: 'vector' does not name a type 8 | vector<int> adj[MAXN]; | ^~~~~~ a.cc:12:1: error: 'vector' does not name a type 12 | vector<int> num; | ^~~~~~ a.cc: In function 'void dfs(int, int)': a.cc:17:20: error: 'adj' was not declared in this scope 17 | for(auto v:adj[u]) | ^~~ a.cc: In function 'void Calc(int, int)': a.cc:35:20: error: 'adj' was not declared in this scope 35 | for(auto v:adj[u]) | ^~~ a.cc: In function 'int main()': a.cc:52:17: error: 'adj' was not declared in this scope 52 | adj[a].push_back(b); | ^~~ a.cc:111:25: error: 'num' was not declared in this scope; did you mean 'sum'? 111 | num.push_back(sum[i]); | ^~~ | sum a.cc:114:9: error: 'num' was not declared in this scope; did you mean 'sum'? 114 | num.push_back(0); | ^~~ | sum
s754350595
p04010
C++
#include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<cstdlib> #include<cassert> #include<ctime> #define cmin(a,b) (a>(b)?a=(b),1:0) #define cmax(a,b) (a<(b)?a=(b),1:0) #define dmin(a,b) ((a)<(b)?(a):(b)) #define dmax(a,b) ((a)>(b)?(a):(b)) namespace io { int F() { int n=0,F=1; char ch; while((ch=getchar())!='-'&&(ch<'0'||ch>'9')); ch=='-'?F=0:n=ch-'0'; while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0'; return F?n:-n; } } struct edge { int to; int next; }e[333333]; int pe=111111; int deg[111111]; void insert(int a,int to) { e[pe]=(edge){to,e[a].next}; e[a].next=pe++; ++deg[to]; } int siz[111111][2]; int c[111111]; int q[111111],hq,tq; int cyc[111111]; long long ans; void dfs(int o,int fa) { siz[o][c[o]]=1,siz[o][!c[o]]=0; for(register int p=e[o].next;p;p=e[p].next) if(e[p].to!=fa) { c[e[p].to]=!c[o]; dfs(e[p].to,o); siz[o][0]+=siz[e[p].to][0]; siz[o][1]+=siz[e[p].to][1]; } int d=dmin(siz[o][0],siz[o][1]); siz[o][0]-=d,siz[o][1]-=d; ans+=siz[o][0]+siz[o][1]; } int pv,cnt[222222][2],d[222222][2]; void dfs2(int o,int fa) { siz[o][0]=1; siz[o][1]=0; for(register int p=e[o].next;p;p=e[p].next) if(e[p].to!=fa&&!cyc[e[p].to]) { dfs2(e[p].to,o); siz[o][0]+=siz[e[p].to][1]; siz[o][1]+=siz[e[p].to][0]; } int d=dmin(siz[o][0],siz[o][1]); siz[o][0]-=d,siz[o][1]-=d; ans+=siz[o][0]+siz[o][1]; } void dfs3(int o,int fa,int top) { dfs2(o,o); ++pv; cnt[pv][0]=siz[o][0]; cnt[pv][1]=siz[o][1]; ans-=siz[o][0]+siz[o][1]; for(register int p=e[o].next;p;p=e[p].next) if(e[p].to!=fa&&e[p].to!=top&&cyc[e[p].to]) { dfs3(e[p].to,o,top); return; } } #define ab(x) ((x)>0?(x):-(x)) int main() { //freopen("reverse.in","r",stdin); //freopen("reverse.out","w",stdout); //int T=io::F(); //while(T--) { pe=111111; for(register int i=1;i<=pe;++i)e[i].next=0; memset(deg,0,sizeof(deg)); int n=io::F(),m=io::F(); for(register int i=1;i<=m;++i) { int x=io::F(),y=io::F(); insert(x,y); insert(y,x); } if(n&1){puts("-1");continue;} if(m==n-1) { ans=0; dfs(1,1); if(siz[1][0]||siz[1][1]){puts("-1");continue;} printf("%lld\n",ans); continue; } else { int md=0; for(register int i=1;i<=n;++i)cmax(md,deg[i]); if(md==2){printf("%d\n",n/2);continue;} hq=tq=1; for(register int i=1;i<=n;++i) if(deg[i]==1)q[tq++]=i,cyc[i]=0; else cyc[i]=1; for(;hq!=tq;++hq) for(register int p=e[q[hq]].next;p;p=e[p].next) if(--deg[e[p].to]==1)q[tq++]=e[p].to,cyc[e[p].to]=0; ans=0; pv=0; for(register int i=1;i<=n;++i) if(cyc[i]){dfs3(i,i,i);break;} int sum=0; for(register int i=1;i<=pv;++i) sum+=cnt[i][0]+cnt[i][1];//cnt[pv+i][0]=cnt[i][0],cnt[pv+i][1]=cnt[i][1]; sum/=2; if((long long)sum*4*pv>=20000000)sum=5000000/pv; long long rr=0x3f3f3f3f3f3f3f3fll; for(register int i=0;i<=sum;++i) { long long tmp=ab(i); for(register int j=1;j<=pv;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; d[pv][0]-=i,d[1][1]+=i; for(register int j=1;j<pv;++j) { int min=dmin(d[j][0],d[j][1]); d[j][0]-=min; d[j][1]-=min; tmp+=ab(d[j][0]+d[j][1]); d[j+1][0]+=d[j][1]; d[j+1][1]+=d[j][0]; } if(d[pv][0]==d[pv][1])cmin(rr,tmp); } for(register int i=0;i<=sum;++i) { long long tmp=ab(i); for(register int j=1;j<=pv+1;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; d[pv][1]-=i,d[1][0]+=i; for(register int j=1;j<pv;++j) { int min=dmin(d[j][0],d[j][1]); d[j][0]-=min; d[j][1]-=min; tmp+=ab(d[j][0]+d[j][1]); d[j+1][0]+=d[j][1]; d[j+1][1]+=d[j][0]; } if(d[pv][0]==d[pv][1])cmin(rr,tmp); } for(register int i=0;i<=sum;++i) { long long tmp=ab(i); for(register int j=1;j<=pv;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; d[pv][0]+=i,d[1][1]-=i; for(register int j=pv;j>1;--j) { int min=dmin(d[j][0],d[j][1]); d[j][0]-=min; d[j][1]-=min; tmp+=ab(d[j][0]+d[j][1]); d[j-1][0]+=d[j][1]; d[j-1][1]+=d[j][0]; } if(d[1][0]==d[1][1])cmin(rr,tmp); } for(register int i=0;i<=sum;++i) { long long tmp=ab(i); for(register int j=1;j<=pv;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; d[pv][1]+=i,d[1][0]-=i; for(register int j=pv;j>1;--j) { int min=dmin(d[j][0],d[j][1]); d[j][0]-=min; d[j][1]-=min; tmp+=ab(d[j][0]+d[j][1]); d[j-1][0]+=d[j][1]; d[j-1][1]+=d[j][0]; } if(d[1][0]==d[1][1])cmin(rr,tmp); } if(rr==0x3f3f3f3f3f3f3f3fll)puts("-1"); else printf("%lld\n",ans+rr); } } return 0; }
a.cc: In function 'void dfs(int, int)': a.cc:45:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 45 | for(register int p=e[o].next;p;p=e[p].next) | ^ a.cc: In function 'void dfs2(int, int)': a.cc:62:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 62 | for(register int p=e[o].next;p;p=e[p].next) | ^ a.cc: In function 'void dfs3(int, int, int)': a.cc:80:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 80 | for(register int p=e[o].next;p;p=e[p].next) | ^ a.cc: In function 'int main()': a.cc:96:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 96 | for(register int i=1;i<=pe;++i)e[i].next=0; | ^ a.cc:99:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 99 | for(register int i=1;i<=m;++i) | ^ a.cc:105:36: error: continue statement not within a loop 105 | if(n&1){puts("-1");continue;} | ^~~~~~~~ a.cc:110:61: error: continue statement not within a loop 110 | if(siz[1][0]||siz[1][1]){puts("-1");continue;} | ^~~~~~~~ a.cc:112:25: error: continue statement not within a loop 112 | continue; | ^~~~~~~~ a.cc:117:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 117 | for(register int i=1;i<=n;++i)cmax(md,deg[i]); | ^ a.cc:118:54: error: continue statement not within a loop 118 | if(md==2){printf("%d\n",n/2);continue;} | ^~~~~~~~ a.cc:120:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 120 | for(register int i=1;i<=n;++i) | ^ a.cc:124:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 124 | for(register int p=e[q[hq]].next;p;p=e[p].next) | ^ a.cc:128:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 128 | for(register int i=1;i<=n;++i) | ^ a.cc:131:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 131 | for(register int i=1;i<=pv;++i) | ^ a.cc:136:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 136 | for(register int i=0;i<=sum;++i) | ^ a.cc:139:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 139 | for(register int j=1;j<=pv;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; | ^ a.cc:141:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 141 | for(register int j=1;j<pv;++j) | ^ a.cc:152:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 152 | for(register int i=0;i<=sum;++i) | ^ a.cc:155:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 155 | for(register int j=1;j<=pv+1;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; | ^ a.cc:157:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 157 | for(register int j=1;j<pv;++j) | ^ a.cc:168:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 168 | for(register int i=0;i<=sum;++i) | ^ a.cc:171:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 171 | for(register int j=1;j<=pv;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; | ^ a.cc:173:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 173 | for(register int j=pv;j>1;--j) | ^ a.cc:184:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 184 | for(register int i=0;i<=sum;++i) | ^ a.cc:187:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 187 | for(register int j=1;j<=pv;++j)d[j][0]=cnt[j][0],d[j][1]=cnt[j][1]; | ^ a.cc:189:50: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 189 | for(register int j=pv;j>1;--j) | ^
s523514812
p04010
C++
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; struct Edge { int v, n; } e[MAXN << 1]; int G[MAXN], edgeCnt; void _add_edge(int u, int v) { e[++edgeCnt].n = G[u]; G[u] = edgeCnt; e[edgeCnt].v = v; } void add_edge(int u, int v) { _add_edge(u, v); _add_edge(v, u); } int n, m; int f[MAXN]; int g[MAXN]; int h[MAXN]; int size[MAXN]; bool vis[MAXN]; int foo, bar; void dfs1(int u, int fa) { size[u] = f[u] ? -1 : 1; size[u] += f[u] ? -h[u] : h[u]; for (int i = G[u]; i; i = e[i].n) if (e[i].v != fa) { if (u == bar && e[i].v == foo || u == foo && e[i].v == bar) { continue; } f[e[i].v] = f[u] ^ 1; dfs1(e[i].v, u); size[u] += size[e[i].v]; g[u] += g[e[i].v]; } } bool dfs2(int u, int fa) { if (vis[u]) return false; vis[u] = true; for (int i = G[u]; i; i = e[i].n) if (e[i].v != fa) { if (!dfs2(e[i].v, u)) foo = u, bar = e[i].v; } return true; } int main() { // freopen("sapphire.in", "r", stdin); // freopen("sapphire.out", "w", stdout); ios::sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; add_edge(u, v); } if (m == n - 1) { dfs1(1, -1); long long ans = 0; for (int i = 1; i <= n; ++i) ans += abs(size[i]); cout << (size[1] == 0 ? ans : -1) << endl; } else { dfs2(1, 0); g[foo] = 1; g[bar] = -1; dfs1(1, 0); long long ans = 0; if (f[foo] == f[bar]) { if (abs(size[1]) & 1) cout << "-1\n"; else { ans += abs(size[1]) / 2; h[foo] = h[bar] = ans; for (int i = 1; i <= n; ++i) dfs1(1, 0); ans += abs(size[i]); cout << ans << endl; } } else { if (size[1] != 0) cout << "-1\n"; else { static int a[MAXN], cnt = 0; for (int i = 1; i <= n; ++i) { if (g[i] == 0) { ans += abs(size[i]); } else { a[++cnt] = -g[i] * size[i]; } } nth_element(a + 1, a + (1 + cnt) / 2, a + cnt + 1); int temp = a[(1 + cnt) / 2]; for (int i = 1; i <= n; ++i) if (g[i] != 0) { ans += abs(size[i] + g[i] * temp); } ans += (f[foo] ^ 1 ? -1 : 1) * temp; cout << ans << endl; } } } }
a.cc: In function 'void dfs1(int, int)': a.cc:36:5: error: reference to 'size' is ambiguous 36 | size[u] = f[u] ? -1 : 1; | ^~~~ 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:1: /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:37:5: error: reference to 'size' is ambiguous 37 | size[u] += f[u] ? -h[u] : h[u]; | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:46:13: error: reference to 'size' is ambiguous 46 | size[u] += size[e[i].v]; | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:46:24: error: reference to 'size' is ambiguous 46 | size[u] += size[e[i].v]; | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc: In function 'int main()': a.cc:79:24: error: reference to 'size' is ambiguous 79 | ans += abs(size[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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:80:18: error: reference to 'size' is ambiguous 80 | cout << (size[1] == 0 ? ans : -1) << endl; | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:88:21: error: reference to 'size' is ambiguous 88 | if (abs(size[1]) & 1) | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:91:28: error: reference to 'size' is ambiguous 91 | ans += abs(size[1]) / 2; | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:95:32: error: reference to 'size' is ambiguous 95 | ans += abs(size[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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:95:37: error: 'i' was not declared in this scope 95 | ans += abs(size[i]); | ^ a.cc:100:17: error: reference to 'size' is ambiguous 100 | if (size[1] != 0) | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:106:36: error: reference to 'size' is ambiguous 106 | ans += abs(size[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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:108:44: error: reference to 'size' is ambiguous 108 | a[++cnt] = -g[i] * size[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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~ a.cc:115:36: error: reference to 'size' is ambiguous 115 | ans += abs(size[i] + g[i] * temp); | ^~~~ /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:29:5: note: 'int size [100010]' 29 | int size[MAXN]; | ^~~~
s586762747
p04010
C++
#include <bits/stdc++.h> #define F(i,j,k) for(int i=(j);i<=(k);++i) using namespace std; const int N=100005; struct V{int head;}v[N]; struct E{int u,v,next;}e[N*2]; int n,m,ecnt=1,degree[N]; inline void add(int x,int y){ e[++ecnt].u=x,e[ecnt].v=y; e[ecnt].next=v[x].head,v[x].head=ecnt; e[++ecnt].u=y,e[ecnt].v=x; e[ecnt].next=v[y].head,v[y].head=ecnt; degree[x]++,degree[y]++; } #define ll long long int size[N]; ll ans; void dfs(int x,int f,int fl){ size[x]+=fl,vis[x]=1; for(int i=v[x].head;i;i=e[i].next){ int y=e[i].v; if(y==f)continue; if(!vis[y])dfs(y,x,fl*-1); size[x]+=size[y]; } ans+=abs(size[x]); } int fa[N]; bool vis[N]; inline int find(int x){return fa[x]=(x==fa[x]?x:find(fa[x]));} inline void uni(int x,int y){fa[find(x)]=find(y);} void get(int x){ for(int i=v[x].head;i;i=e[i].next){ int y=e[i].v; if(!fa[y])fa[y]=x,get(y); } } int main(){ //freopen("txt.in","r",stdin);freopen("txt.out","w",stdout); scanf("%d %d\n",&n,&m); int tu,tv; int U,V; F(i,1,m){ scanf("%d %d\n",&tu,&tv),add(tu,tv); if(find(tu)==find(tv))U=tu,V=tv; else uni(tu,tv); } if(n==m){ memset(fa,0,sizeof(fa)); get(U); int top=0,s[N]; for(int i=V;i;i=fa[i])s[++top]=i; if(top&1){ dfs(U,0,1); int temp=size[U]; if(temp%2){printf("-1\n");return 0;} else{ F(i,1,n)size[U]=0; size[U]-=temp/2,size[V]-=temp/2; memset(vis,0,sizeof(vis)); dfs(U,0,1); printf("%lld\n",ans+temp/2); } } else{ } } else{ F(i,1,n)if(degree[i]==1){ dfs(i,0,1); if(!size[i])printf("%lld\n",ans); else printf("-1\n"); return 0; } } return 0; }
a.cc: In function 'void dfs(int, int, int)': a.cc:19:9: error: reference to 'size' is ambiguous 19 | size[x]+=fl,vis[x]=1; | ^~~~ 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:1: /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc:19:21: error: 'vis' was not declared in this scope 19 | size[x]+=fl,vis[x]=1; | ^~~ a.cc:24:17: error: reference to 'size' is ambiguous 24 | size[x]+=size[y]; | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc:24:26: error: reference to 'size' is ambiguous 24 | size[x]+=size[y]; | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc:26:18: error: reference to 'size' is ambiguous 26 | ans+=abs(size[x]); | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc: In function 'int main()': a.cc:55:34: error: reference to 'size' is ambiguous 55 | int temp=size[U]; | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc:58:41: error: reference to 'size' is ambiguous 58 | F(i,1,n)size[U]=0; | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc:59:33: error: reference to 'size' is ambiguous 59 | size[U]-=temp/2,size[V]-=temp/2; | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc:59:49: error: reference to 'size' is ambiguous 59 | size[U]-=temp/2,size[V]-=temp/2; | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~ a.cc:72:29: error: reference to 'size' is ambiguous 72 | if(!size[i])printf("%lld\n",ans); | ^~~~ /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:16:5: note: 'int size [100005]' 16 | int size[N]; | ^~~~
s164445449
p04010
C++
#include<iostream> #include<cstring> #include<cstdio> #define MN 100000 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,m,head[MN+5],cnt=1,ans=0,f[MN+5],g[MN+5][2],Fa[MN+5],dep[MN+5],A,B,C,c[MN+5],num,mn=1e9,q[MN+5],top; 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; } inline int Abs(int x){return x<0?-x:x;} void dfs(int x,int fa=0) { ++g[x][f[x]]; for(int i=head[x];i;i=e[i].next) if(e[i].to!=fa) { if(x==A&&e[i].to==B) continue; if(x==B&&e[i].to==A) continue; f[e[i].to]=f[x]^1;dfs(e[i].to,x); g[x][0]+=g[e[i].to][0]; g[x][1]+=g[e[i].to][1]; } ans+=Abs(g[x][0]-g[x][1]); } void FindCircle(int x,int fa) { Fa[x]=fa; for(int i=head[x];i;i=e[i].next) if(e[i].to!=fa) { if(dep[e[i].to]) A=x,B=e[i].to; else dep[e[i].to]=dep[x]+1,FindCircle(e[i].to,x); } } int main() { n=read();m=read();if(n&1) return 0*puts("-1"); if(m<n) { for(int i=1;i<n;++i) ins(read(),read()); dfs(1); printf("%d\n",g[1][0]==g[1][1]?ans:-1); } else { for(int i=1;i<=n;++i) ins(read(),read()); FindCircle(dep[1]=1,0); for(int x=A,y=B;x!=y;C=x=Fa[x]) if(dep[x]<dep[y]) swap(x,y); for(int i=A;i!=C;i=Fa[i]) c[++num]=i; c[++num]=C;int len=dep[A]+dep[B]-2*dep[C]+1;num=len; for(int i=B;i!=C;i=Fa[i]) c[len--]=i; if(dfs(1),num&1) { if(Abs(g[1][1]-g[1][0])&1) return 0*puts("-1"); int dif=(g[1][1]-g[1][0])/2;ans=Abs(dif); for(int i=A;i;i=Fa[i]) g[i][0]+=dif; for(int i=B;i;i=Fa[i]) g[i][0]+=dif; for(int i=1;i<=n;++i) ans+=Abs(g[i][0]-g[i][1]); printf("%d\n",ans); } else { if(g[1][0]!=g[1][1]) return 0*puts("-1"); for(int i=A;i!=C;i=Fa[i]) q[++top]=g[i][0]-g[i][1]; for(int i=B;i!=C;i=Fa[i]) q[++top]=g[i][1]-g[i][0]; sort(q+1,q+top+1); int res; if(top&1) res=q[(top+1)/2]; else res=Abs(q[top/2])<Abs(q[top/2+1])?q[top/2]:q[top/2+1]; res=-res; for(int i=A;i;i=Fa[i]) g[i][0]+=res; for(int i=B;i;i=Fa[i]) g[i][1]+=res; ans=Abs(res);for(int i=1;i<=n;++i) ans+=Abs(g[i][0]-g[i][1]); printf("%d\n",ans); } } return 0; }
a.cc: In function 'int main()': a.cc:77:13: error: 'sort' was not declared in this scope; did you mean 'short'? 77 | sort(q+1,q+top+1); | ^~~~ | short
s158034552
p04010
C++
// +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+ \\ #include <bits/stdc++.h> #define F first #define S second #define _sz(x) (int)x.size() using namespace std ; using ll = long long ; using ld = long double ; using pii = pair <int , int> ; int const N = 1e5 + 20 ; int n , m ; vector <int> g[N] ; struct edge { int u , v ; bool in ; } e[N] ; vector <int> vec ; int d , ans , h[N] ; bool vis[N] ; int dfs (int v) { int d = 1 ; vis[v] = 1 ; for (int i : g[v]) { int u = e[i].u ^ e[i].v ^ v ; if (!vis[u]) { e[i].in = 1 ; h[u] = h[v] ^ 1 ; d -= dfs(u) ; } } vec.push_back(d) ; ans += abs(d) ; return d ; } int token[N] ; int want = -1 ; int get (int v , int par = -1) { int d = 0 ; if (h[v] != want) d ++ ; d -= token[v] ; for (int i : g[v]) { int u = e[i].u ^ e[i].v ^ v ; if (e[i].in && u != par) { d += get(u , v) ; } } ans += abs(d) ; return d ; } int main(){ ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ; cin >> n >> m ; for (int i = 0 ; i < m ; i ++) { cin >> e[i].u >> e[i].v ; e[i].u -- , e[i].v -- ; g[e[i].u].push_back(i) ; g[e[i].v].push_back(i) ; } d = dfs(0) ; if (m == n - 1) { if (!d) cout << ans << '\n' ; else cout << "-1\n" , 0 ; return 0 ; } bool odd_cycle = 0 ; for (int i = 0 ; i < m ; i ++) if (!e[i].in && h[e[i].u] == h[e[i].v]) odd_cycle = 1 ; if (odd_cycle) { if (d & 1) return cout << "-1\n" , 0 ; d /= 2 ; for (int i = 0 ; i < m ; i ++) if (!e[i].in) want = h[e[i].u] , token[e[i].u] = token[e[i].v] = (h[e[i].u] ? -d : d) ; for (int i = 0 ; i < n ; i ++) if (h[i] == want) token[i] ++ ; ans = abs(d) ; get(0) ; cout << ans << '\n' ; } else { if (d) return cout << "-1\n" , 0 ; assert(0) ; sort(vec.begin() , vec.end()) ; int x = vec[(n - 1) / 2] ; ans += x * (n - 1) + x ; cout << ans << '\n' ; } } // +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+ \\ #include <bits/stdc++.h> #define F first #define S second #define _sz(x) (int)x.size() using namespace std ; using ll = long long ; using ld = long double ; using pii = pair <int , int> ; int const N = 1e5 + 20 ; int n , m ; vector <int> g[N] ; struct edge { int u , v ; bool in ; } e[N] ; vector <int> vec ; int d , ans , h[N] ; bool vis[N] ; int dfs (int v) { int d = 1 ; vis[v] = 1 ; for (int i : g[v]) { int u = e[i].u ^ e[i].v ^ v ; if (!vis[u]) { e[i].in = 1 ; h[u] = h[v] ^ 1 ; d -= dfs(u) ; } } vec.push_back(d) ; ans += abs(d) ; return d ; } int token[N] ; int want = -1 ; int get (int v , int par = -1) { int d = 0 ; if (h[v] != want) d ++ ; d -= token[v] ; for (int i : g[v]) { int u = e[i].u ^ e[i].v ^ v ; if (e[i].in && u != par) { d += get(u , v) ; } } ans += abs(d) ; return d ; } int main(){ ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ; cin >> n >> m ; for (int i = 0 ; i < m ; i ++) { cin >> e[i].u >> e[i].v ; e[i].u -- , e[i].v -- ; g[e[i].u].push_back(i) ; g[e[i].v].push_back(i) ; } d = dfs(0) ; if (m == n - 1) { if (!d) cout << ans << '\n' ; else cout << "-1\n" , 0 ; return 0 ; } bool odd_cycle = 0 ; for (int i = 0 ; i < m ; i ++) if (!e[i].in && h[e[i].u] == h[e[i].v]) odd_cycle = 1 ; if (odd_cycle) { if (d & 1) return cout << "-1\n" , 0 ; d /= 2 ; for (int i = 0 ; i < m ; i ++) if (!e[i].in) want = h[e[i].u] , token[e[i].u] = token[e[i].v] = -d ; for (int i = 0 ; i < n ; i ++) if (h[i] == want) token[i] ++ ; ans = abs(d) ; get(0) ; cout << ans << '\n' ; } else { if (d) return cout << "-1\n" , 0 ; assert(0) ; sort(vec.begin() , vec.end()) ; int x = vec[(n - 1) / 2] ; ans += x * (n - 1) + x ; cout << ans << '\n' ; } }
a.cc:132:11: error: redefinition of 'const int N' 132 | int const N = 1e5 + 20 ; | ^ a.cc:14:11: note: 'const int N' previously defined here 14 | int const N = 1e5 + 20 ; | ^ a.cc:133:5: error: redefinition of 'int n' 133 | int n , m ; | ^ a.cc:15:5: note: 'int n' previously declared here 15 | int n , m ; | ^ a.cc:133:9: error: redefinition of 'int m' 133 | int n , m ; | ^ a.cc:15:9: note: 'int m' previously declared here 15 | int n , m ; | ^ a.cc:134:14: error: redefinition of 'std::vector<int> g [100020]' 134 | vector <int> g[N] ; | ^ a.cc:16:14: note: 'std::vector<int> g [100020]' previously declared here 16 | vector <int> g[N] ; | ^ a.cc:136:8: error: redefinition of 'struct edge' 136 | struct edge { | ^~~~ a.cc:18:8: note: previous definition of 'struct edge' 18 | struct edge { | ^~~~ a.cc:139:3: error: conflicting declaration 'int e [100020]' 139 | } e[N] ; | ^ a.cc:21:3: note: previous declaration as 'edge e [100020]' 21 | } e[N] ; | ^ a.cc:141:14: error: redefinition of 'std::vector<int> vec' 141 | vector <int> vec ; | ^~~ a.cc:23:14: note: 'std::vector<int> vec' previously declared here 23 | vector <int> vec ; | ^~~ a.cc:142:5: error: redefinition of 'int d' 142 | int d , ans , h[N] ; | ^ a.cc:24:5: note: 'int d' previously declared here 24 | int d , ans , h[N] ; | ^ a.cc:142:9: error: redefinition of 'int ans' 142 | int d , ans , h[N] ; | ^~~ a.cc:24:9: note: 'int ans' previously declared here 24 | int d , ans , h[N] ; | ^~~ a.cc:142:15: error: redefinition of 'int h [100020]' 142 | int d , ans , h[N] ; | ^ a.cc:24:15: note: 'int h [100020]' previously declared here 24 | int d , ans , h[N] ; | ^ a.cc:143:6: error: redefinition of 'bool vis [100020]' 143 | bool vis[N] ; | ^~~ a.cc:25:6: note: 'bool vis [100020]' previously declared here 25 | bool vis[N] ; | ^~~ a.cc:145:5: error: redefinition of 'int dfs(int)' 145 | int dfs (int v) { | ^~~ a.cc:27:5: note: 'int dfs(int)' previously defined here 27 | int dfs (int v) { | ^~~ a.cc:163:5: error: redefinition of 'int token [100020]' 163 | int token[N] ; | ^~~~~ a.cc:45:5: note: 'int token [100020]' previously declared here 45 | int token[N] ; | ^~~~~ a.cc:164:5: error: redefinition of 'int want' 164 | int want = -1 ; | ^~~~ a.cc:46:5: note: 'int want' previously defined here 46 | int want = -1 ; | ^~~~ a.cc:166:5: error: redefinition of 'int get(int, int)' 166 | int get (int v , int par = -1) { | ^~~ a.cc:48:5: note: 'int get(int, int)' previously defined here 48 | int get (int v , int par = -1) { | ^~~ a.cc:183:5: error: redefinition of 'int main()' 183 | int main(){ | ^~~~ a.cc:65:5: note: 'int main()' previously defined here 65 | int main(){ | ^~~~
s306369395
p04010
C++
// +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+ \\ #include <bits/stdc++.h> #define F first #define S second #define _sz(x) (int)x.size() using namespace std ; using ll = long long ; using ld = long double ; using pii = pair <int , int> ; int const N = 1e5 + 20 ; int n , m ; vector <int> g[N] ; struct edge { int u , v ; bool in ; } e[N] ; vector <int> vec ; int d , ans , h[N] ; bool vis[N] ; int dfs (int v) { int d = 1 ; vis[v] = 1 ; for (int i : g[v]) { int u = e[i].u ^ e[i].v ^ v ; if (!vis[u]) { e[i].in = 1 ; h[u] = h[v] ^ 1 ; d -= dfs(u) ; } } vec.push_back(d) ; ans += abs(d) ; return d ; } int token[N] ; int want = -1 ; int get (int v , int par = -1) { int d = 0 ; if (h[v] != want) d ++ ; d -= token[v] ; for (int i : g[v]) { int u = e[i].u ^ e[i].v ^ v ; if (e[i].in && u != par) { d += get(u , v) ; } } ans += abs(d) ; return d ; } int main(){ ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ; cin >> n >> m ; for (int i = 0 ; i < m ; i ++) { cin >> e[i].u >> e[i].v ; e[i].u -- , e[i].v -- ; g[e[i].u].push_back(i) ; g[e[i].v].push_back(i) ; } d = dfs(0) ; if (m == n - 1) { if (!d) cout << ans << '\n' ; else cout << "-1\n" , 0 ; return 0 ; } bool odd_cycle = 0 ; for (int i = 0 ; i < m ; i ++) if (!e[i].in && h[e[i].u] == h[e[i].v]) odd_cycle = 1 ; if (odd_cycle) { if (d & 1) return cout << "-1\n" , 0 ; d /= 2 ; for (int i = 0 ; i < m ; i ++) if (!e[i].in) want = h[e[i].u] , token[e[i].u] = token[e[i].v] = -d ; for (int i = 0 ; i < n ; i ++) if (h[i] == want) token[i] ++ ; ans = abs(d) ; get(0) ; cout << ans << '\n' ; } else { if (d) return cout << "-1\n" , 0 ; assert(0) ; sort(vec.begin() , vec.end()) ; ans = x ; for (int i = 0 ; i < n - 1 ; i ++) ans += abs( int x = vec[(n - 1) / 2] ; ans += x * (n - 1) + x ; cout << ans << '\n' ; } }
a.cc: In function 'int main()': a.cc:113:23: error: 'x' was not declared in this scope 113 | ans = x ; | ^ a.cc:117:17: error: expected primary-expression before 'int' 117 | int x = vec[(n - 1) / 2] ; | ^~~
s223535972
p04010
C++
// Namori // * frank_c1 // * 2017 / 12 / 18 #include <bits/stdc++.h> using namespace std; const int maxn = (int)(1e5) + 5; vector<int> nxt[maxn]; int fa[maxn], dfn[maxn], siz[maxn], su[maxn]; int ci[maxn], cc[maxn], va[maxn]; int cnt, idx; inline int iabs(int x) { return x >= 0 ? x : -x; } void dfs(int x, int f, int v) { fa[x] = f; dfn[x] = ++idx; siz[x] = 1; su[x] = v; v ^= 1; for (int i = 0; i < (int)nxt[x].size(); ++i) if (nxt[x][i] != f) { if (!dfn[nxt[x][i]]) { dfs(nxt[x][i], x, v); su[x] += su[nxt[x][i]]; siz[x] += siz[nxt[x][i]]; } else if (dfn[nxt[x][i]] < dfn[x]) { int c = x, a = nxt[x][i]; while (c != a) { ci[++cnt] = c; cc[c] = 1; c = fa[c]; } ++cnt; } } } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); nxt[u].push_back(v); nxt[v].push_back(u); } dfs(1, 0, 0); if (!cnt || !(cnt & 1)) { if (2 * su[1] != siz[1]) { printf("-1\n"); return; } } else { if ((2 * su[1] - siz[1]) & 1) { printf("-1\n"); return; } } int dt = (2 * su[1] - siz[1]) / 2, ret = 0; for (int i = 1; i <= n; ++i) if (!cc[i]) ret += iabs(2 * su[i] - siz[i]); if (cnt) { for (int i = 1; i < cnt; ++i) va[i] = 2 * su[ci[i]] - siz[ci[i]]; va[cnt] = 0; sort(va + 1, va + cnt + 1); ret += iabs(va[(cnt + 1) / 2]) + iabs(dt); for (int i = 1; i < cnt; ++i) ret += iabs(va[(cnt + 1) / 2] - dt - 2 * su[ci[i]] + siz[ci[i]]); } printf("%d\n", ret); return 0; }
a.cc: In function 'int main()': a.cc:47:41: error: return-statement with no value, in function returning 'int' [-fpermissive] 47 | printf("-1\n"); return; | ^~~~~~ a.cc:51:41: error: return-statement with no value, in function returning 'int' [-fpermissive] 51 | printf("-1\n"); return; | ^~~~~~
s270744947
p04010
C++
// Namori // * frank_c1 // * 2017 / 12 / 18 #include <bits/stdc++.h> using namespace std; const int maxn = (int)(1e5) + 5; vector<int> nxt[maxn]; int fa[maxn], dfn[maxn], siz[maxn]; int cnt; void dfs(int x, int f) { fa[x] = f; siz[x] = 1; dfn[x] = ++idx; for (int i = 0; i < (int)nxt[x].size(); ++i) if (nxt[x][i] != f) { if (!dfn[nxt[x][i]]) { dfs(nxt[x][i], x); siz[x] += siz[nxt[x][i]]; } else if (dfn[nxt[x][i]] < dfn[x]) { cnt = 1; int c = x, a = nxt[x][i]; while (c != a) { ++cnt; c = fa[c]; } } } } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); nxt[u].push_back(v); nxt[v].push_back(u); } dfs(1, 0); if (!cnt) { if (n & 1) { printf("-1\n"); } else { int ret = 0; for (int i = 1; i <= n; ++i) ret += (siz[i] & 1); printf("%d\n", ret); } } else if (!(cnt & 1)) { } else { } return 0; }
a.cc: In function 'void dfs(int, int)': a.cc:14:43: error: 'idx' was not declared in this scope 14 | fa[x] = f; siz[x] = 1; dfn[x] = ++idx; | ^~~
s140077807
p04010
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10; int n,m,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 c1[N],c2[N];ll dp[N]; void dfs(int x,int h,int fa){ (h&1?c1[x]:c2[x])=1; for (int i=head[x];i;i=next[i]) if (w[i]!=fa){ int v=w[i]; dfs(v,h+1,x); dp[x]+=dp[v]+abs(c1[v]-c2[v]); c1[x]+=c1[v]; c2[x]+=c2[v]; } } int main() { scanf("%d%d",&n,&m); for (int i=1;i<n;i++){ int u,v; scanf("%d%d",&u,&v); add(u,v);add(v,u); } dfs(1,0,0); printf("%lld\n",c1[1]==c2[1]?dp[1]:-1ll); return 0; }
a.cc: In function 'void add(int, int)': a.cc:9:9: error: reference to 'next' is ambiguous 9 | 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:5:22: note: 'int next [200010]' 5 | int n,m,w[N],head[N],next[N]; | ^~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:15:32: error: reference to 'next' is ambiguous 15 | 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:5:22: note: 'int next [200010]' 5 | int n,m,w[N],head[N],next[N]; | ^~~~
s356701935
p04010
C++
#include<iostream> #include<vector> #include<algorithm> #include<cstring> #include<cstdio> #include<cmath> #include<cstdlib> #include<ctime> #include<queue> #include<set> #include<map> #include<stack> using namespace std; typedef long long LL; const int N=2e5; int gi() { int w=0;bool q=1;char c=getchar(); while ((c<'0'||c>'9') && c!='-') c=getchar(); if (c=='-') q=0,c=getchar(); while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar(); return q? w:-w; } int head[N],next[N],to[N],st[N]; int fa[N];inline int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); } int ans,sum[N],siz[N]; bool vis[N]; inline int dfs(int k) { int t; for (int i=head[k];i;i=next[i]) if (!vis[to[i]]) { vis[to[i]]=true; t=dfs(to[i]); ans+=abs(t); siz[k]-=t; } return siz[k]; } inline void get(int k) { for (int i=head[k];i;i=next[i]) if (to[i]!=fa[k]) fa[to[i]]=k,get(to[i]); } int main() { int n=gi(),m=gi(),i,tot=0,a,b,A,B,top=0,t,k; for (i=1;i<=n;i++) fa[i]=i,siz[i]=1; for (i=1;i<=m;i++) { a=gi(),b=gi(); if (find(a)==find(b)) A=a,B=b; else { fa[fa[a]]=b; to[++tot]=b,next[tot]=head[a],head[a]=tot; to[++tot]=a,next[tot]=head[b],head[b]=tot; } } if (m==n-1) vis[1]=true,printf("%d\n",dfs(1)?-1:ans); else { for (i=1;i<=n;i++) fa[i]=0; get(A); for (k=B;k;k=fa[k]) st[++top]=k; if (top&1) { vis[A]=true;t=dfs(A); for (i=1;i<=n;i++) vis[i]=false,siz[i]=1; if (t%2) return puts("-1"),0; siz[A]-=t/2,siz[B]-=t/2; ans=abs(t/2); vis[A]=true;dfs(A); } else { for (i=1;i<=top;i++) vis[st[i]]=true; for (i=1;i<=top;i++) sum[i]=sum[i-1]+(i&1?-1:1)*dfs(st[i]); sort(sum+1,sum+1+top); for (i=1;i<=top;i++) ans+=abs(sum[top/2]-sum[i]); } printf("%d\n",ans); } return 0; }
a.cc: In function 'int dfs(int)': a.cc:29:32: error: reference to 'next' is ambiguous 29 | for (int i=head[k];i;i=next[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: 'int next [200000]' 23 | int head[N],next[N],to[N],st[N]; | ^~~~ a.cc: In function 'void get(int)': a.cc:39:32: error: reference to 'next' is ambiguous 39 | for (int i=head[k];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:23:13: note: 'int next [200000]' 23 | int head[N],next[N],to[N],st[N]; | ^~~~ a.cc: In function 'int main()': a.cc:52:37: error: reference to 'next' is ambiguous 52 | to[++tot]=b,next[tot]=head[a],head[a]=tot; | ^~~~ /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: 'int next [200000]' 23 | int head[N],next[N],to[N],st[N]; | ^~~~ a.cc:53:37: error: reference to 'next' is ambiguous 53 | to[++tot]=a,next[tot]=head[b],head[b]=tot; | ^~~~ /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: 'int next [200000]' 23 | int head[N],next[N],to[N],st[N]; | ^~~~
s846741793
p04010
C++
#include <bits/stdc++.h> using namespace std; const int Maxn=1e5+10; struct EDGE{int x,y,next;}edge[Maxn*2]; int len,first[Maxn]; void ins(int x,int y){len++; edge[len].x=x; edge[len].y=y; edge[len].next=first[x]; first[x]=len;} int N,M; int C[Maxn]; int u,v,opt; bool vis[Maxn]; void Find_Cir(int x,int fa,int col) { C[x]=col; vis[x]=1; for(int k=first[x];k!=-1;k=edge[k].next) { int y=edge[k].y; if(x==u&&y==v) continue; if(y!=fa) { if(vis[y]){u=x; v=y; if(C[u]==C[v]) opt=1; else opt=0;} else Find_Cir(y,x,-col); } } } int G[Maxn],F[Maxn]; void Dfs(int x,int fa) { F[x]=C[x]; for(int k=first[x];k!=-1;k=edge[k].next) { int y=edge[k].y; if(x==u&&y==v) continue; if(x==v&&y==u) continue; if(y!=fa) { Dfs(y,x); F[x]+=F[y]; G[x]+=G[y]; } } } int A[Maxn]; int Alen; int main() { int Tcase=1 while(Tcase--) { scanf("%d%d",&N,&M); len=0; memset(first,-1,sizeof(first)); for(int i=1;i<=M;i++){int x,y; scanf("%d%d",&x,&y); ins(x,y); ins(y,x);} memset(vis,0,sizeof(vis)); memset(C,0,sizeof(C)); u=v=0; Find_Cir(1,0,1); if(M==N-1) { Dfs(1,0); if(F[1]) printf("-1\n"); else{int ans=0; for(int i=1;i<=N;i++) ans+=abs(F[i]); printf("%d\n",ans);} } else if(opt==1) { Dfs(1,0); int t=F[1],ans=0; if(t&1) printf("-1\n"); else { C[u]-=t/2; C[v]-=t/2; ans+=abs(t/2); memset(F,0,sizeof F); Dfs(1,0); for(int i=1;i<=N;i++) ans+=abs(F[i]); printf("%d\n",ans); } } else if(opt==0) { Dfs(1,0); if(F[1]) printf("-1\n"); else { memset(G,0,sizeof(G)); G[u]--; G[v]++; memset(F,0,sizeof F); Dfs(1,0); int ans=0; Alen=0; memset(A,0,sizeof(A)); for(int i=1;i<=N;i++) { if(G[i]==-1) A[++Alen]=F[i]; if(G[i]==0) ans+=abs(F[i]); if(G[i]==1) A[++Alen]=-F[i]; } sort(A+1,A+Alen+1); for(int i=1;i<=Alen;i++) ans+=abs(A[i]-A[(Alen+1)>>1]); ans+=abs(A[(Alen+1)>>1]); printf("%d\n",ans); } } } return 0; }
a.cc: In function 'int main()': a.cc:46:3: error: expected ',' or ';' before 'while' 46 | while(Tcase--) | ^~~~~
s441988981
p04010
C++
#include<set> #include<map> #include<deque> #include<queue> #include<stack> #include<cmath> #include<ctime> #include<bitset> #include<string> #include<vector> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<complex> #include<iostream> #include<algorithm> #define ll long long #define inf 1e9 using namespace std; const int maxn = 101000; int n,m; struct edge { int y,nex; edge(){} edge(const int _y,const int _nex){y=_y;nex=_nex;} }a[maxn<<1]; int len, fir[maxn]; bool e[maxn<<1]; inline void ins(const int x,const int y){a[++len]=edge(y,fir[x]);fir[x]=len;} int cir[maxn],cn; bool inc[maxn]; int t[maxn],tp; bool v[maxn]; bool f_cir(const int x,const int pre) { if(v[x]) { int la=0; while(la!=x) inc[cir[++cn]=la=t[tp--]]=true; return true; } v[x]=true; t[++tp]=x; for(int k=fir[x];k;k=a[k].nex) if(k!=(pre^1)) { if(f_cir(a[k].y,k)) return true; } tp--; return false; } int col[maxn],num[2]; void Color(const int x,const int ff) { num[col[x]==1]++; for(int k=fir[x];k;k=a[k].nex) { const int y=a[k].y; if(inc[y]||y==ff) continue; col[y]=col[x]==1?-1:1; Color(y,x); } } int s[maxn],o[maxn]; int dfs(const int x,const int ff) { s[x]=0; int re=col[x]; for(int k=fir[x];k;k=a[k].nex)if(!e[k]) { const int y=a[k].y; if(inc[y]||y==ff) continue; int tmp=dfs(y,x); s[x]+=s[y]+abs(tmp); re+=tmp; } return re; } int solve() { t[tp=1]=0; int la=0; for(int i=2;i<=cn;i++) { t[++tp]=-la-o[cir[i]]; la+=o[cir[i]]; } sort(t+1,t+tp+1); int ans=0,A=t[1+(tp>>1)]; for(int i=1;i<=tp;i++) ans+=abs(A-t[i]); return ans; } int main() { len=1; memset(fir,0,sizeof fir); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) inc[i]=false; for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); ins(x,y); ins(y,x); } num[0]=num[1]=0; if(n==m+1) { col[1]=-1; Color(1,0); if(num[0]!=num[1]) { printf("-1\n"); continue; } int k=dfs(1,0); printf("%d\n",s[1]); } else { cn=0; tp=0; for(int i=1;i<=n;i++) v[i]=false; f_cir(a[2].y,2); for(int i=1;i<=cn;i++) col[cir[i]]=(i&1)?1:-1,Color(cir[i],0); if(cn&1) { if((num[0]&1)!=(num[1]&1)) { printf("-1\n"); continue; } if(num[0]<num[1]) { swap(num[0],num[1]); for(int i=1;i<=n;i++) col[i]=col[i]==1?-1:1; } int ek,re=0; for(int k=fir[cir[1]];k;k=a[k].nex) if(a[k].y==cir[cn]) { e[ek=k]=true; e[ek^1]=true; int tmp=(num[0]-num[1])>>1; col[cir[1]]+=tmp; col[cir[cn]]+=tmp; re+=tmp; break; } for(int i=1;i<=cn;i++) inc[cir[i]]=false; int k=dfs(1,0); e[ek]=false; e[ek^1]=false; printf("%d\n",re+s[1]); } else { if(num[0]!=num[1]) { printf("-1\n"); continue; } int re=0; for(int i=1;i<=cn;i++) o[cir[i]]=dfs(cir[i],0),re+=s[cir[i]]; printf("%d\n",re+solve()); } } return 0; }
a.cc: In function 'int main()': a.cc:116:62: error: continue statement not within a loop 116 | if(num[0]!=num[1]) { printf("-1\n"); continue; } | ^~~~~~~~ a.cc:128:78: error: continue statement not within a loop 128 | if((num[0]&1)!=(num[1]&1)) { printf("-1\n"); continue; } | ^~~~~~~~ a.cc:151:70: error: continue statement not within a loop 151 | if(num[0]!=num[1]) { printf("-1\n"); continue; } | ^~~~~~~~
s572809305
p04010
C++
/+ dub.sdl: name "A" dependency "dcomp" version=">=0.4.0" +/ import std.stdio, std.algorithm, std.conv, std.range; import std.typecons, std.math; // import dcomp.scanner, dcomp.graph.namori; alias E = Tuple!(int, "to"); long solve(E[][] g) { int n = g.length.to!int; if (n % 2) return 10L^^18; int[] sz = new int[n]; int[] csm = new int[n]; long ans = 0; void dfs(int p, int b, bool c) { sz[p] = 1; if (c) csm[p] = 1; foreach (e; g[p]) { int d = e.to; if (d == b) continue; dfs(d, p, !c); sz[p] += sz[d]; csm[p] += csm[d]; } ans += abs(sz[p] - 2*csm[p]); } dfs(0, -1, 0); return ans; } int main() { auto sc = new Scanner(stdin); int n, m; sc.read(n, m); E[][] g = new E[][n]; foreach (i; 0..m) { int a, b; sc.read(a, b); a--; b--; g[a] ~= E(b); g[b] ~= E(a); } if (n % 2) { writeln(0); return 0; } if (m == n-1) { //not namori writeln(solve(g)); } return 0; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/namori.d */ // module dcomp.graph.namori; // import dcomp.graph.dfsinfo; struct Namori { bool[] isCycle; int[][] cycles; int[] root; this(int n) { isCycle = new bool[n]; root = new int[n]; } } Namori namori(T)(T g) { import std.algorithm : find, each; import std.range; import std.conv : to; int n = g.length.to!int; auto info = dfsInfo(g); auto nmr = Namori(n); with (nmr) { //find self loop foreach (i; 0..n) { if (g[i].find!(e => e.to == i).empty) continue; isCycle[i] = true; cycles ~= [i]; } foreach (p; info.vlis) { if (info.low[p] == info.ord[p]) continue; if (g[p].length == info.tr[p].length+1) continue; int[] v; int nw = p; while (info.ord[nw] != info.low[p]) { v ~= nw; nw = info.par[nw]; } v ~= nw; v.each!(i => isCycle[i] = true); cycles ~= v; } bool[] used = new bool[n]; void dfs(int p, int b, int r) { if (used[p]) return; used[p] = true; root[p] = r; foreach (e; g[p]) { int d = e.to; if (d == b) continue; if (isCycle[d]) continue; dfs(d, p, r); } } foreach (i; 0..n) { if (!isCycle[i]) continue; dfs(i, -1, i); } } return nmr; } Namori directedNamori(int[] g) { import std.algorithm : find, each; import std.range; import std.conv : to; int n = g.length.to!int; auto nmr = Namori(n); with (nmr) { int[] used = new int[n]; used[] = -1; foreach (i; 0..n) { if (used[i] != -1) continue; int j = i; while (used[j] == -1) { used[j] = i; j = g[j]; } if (used[j] != i) continue; int k = j; int[] cy = []; while (true) { cy ~= k; isCycle[k] = true; if (g[k] == j) break; k = g[k]; } cycles ~= cy; } int[] dp = new int[n]; dp[] = -1; int dfs(int p) { if (isCycle[p]) return p; if (dp[p] != -1) return dp[p]; return dp[p] = dfs(g[p]); } foreach (i; 0..n) { root[i] = dfs(i); } } return nmr; } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */ // module dcomp.scanner; class Scanner { import std.stdio : File; import std.conv : to; import std.range : front, popFront, array, ElementType; import std.array : split; import std.traits : isSomeChar, isStaticArray, isArray; import std.algorithm : map; File f; this(File f) { this.f = f; } string[] buf; private bool succ() { while (!buf.length) { if (f.eof) return false; buf = f.readln.split; } return true; } private bool readSingle(T)(ref T x) { if (!succ()) return false; static if (isArray!T) { alias E = ElementType!T; static if (isSomeChar!E) { //string or char[10] etc x = buf.front; buf.popFront; } else { static if (isStaticArray!T) { //static assert(buf.length == T.length); } x = buf.map!(to!E).array; buf.length = 0; } } else { x = buf.front.to!T; buf.popFront; } return true; } int read(T, Args...)(ref T x, auto ref Args args) { if (!readSingle(x)) return 0; static if (args.length == 0) { return 1; } else { return 1 + read(args); } } } unittest { import std.path : buildPath; import std.file : tempDir; import std.algorithm : equal; import std.stdio : File; string fileName = buildPath(tempDir, "kyuridenanmaida.txt"); auto fout = File(fileName, "w"); fout.writeln("1 2 3"); fout.writeln("ab cde"); fout.writeln("1.0 1.0 2.0"); fout.close; Scanner sc = new Scanner(File(fileName, "r")); int a; int[2] b; char[2] c; string d; double e; double[] f; sc.read(a, b, c, d, e, f); assert(a == 1); assert(equal(b[], [2, 3])); assert(equal(c[], "ab")); assert(equal(d, "cde")); assert(e == 1.0); assert(equal(f, [1.0, 2.0])); } /* IMPORT /home/yosupo/Program/dcomp/source/dcomp/graph/dfsinfo.d */ // module dcomp.graph.dfsinfo; struct DFSInfo { int[] low, ord, par, vlis; //low, ord, parent, visitList int[][] tr; //dfs tree(directed) this(int n) { low = new int[n]; ord = new int[n]; par = new int[n]; vlis = new int[n]; tr = new int[][](n); } } DFSInfo dfsInfo(T)(T g) { import std.algorithm : min, each, filter; import std.conv : to; const int n = g.length.to!int; auto info = DFSInfo(n); with(info) { int co = 0; bool[] used = new bool[](n); void dfs(int p, int b) { used[p] = true; low[p] = ord[p] = co++; par[p] = b; bool rt = true; foreach (e; g[p]) { int d = e.to; if (rt && d == b) { rt = false; continue; } if (!used[d]) { dfs(d, p); low[p] = min(low[p], low[d]); } else { low[p] = min(low[p], ord[d]); } } } foreach (i; 0..n) { if (used[i]) continue; dfs(i, -1); } par.filter!"a!=-1".each!((i, v) => tr[v] ~= i.to!int); ord.each!((i, v) => vlis[v] = i.to!int); } return info; }
a.cc:41:17: error: too many decimal points in number 41 | foreach (i; 0..m) { | ^~~~ a.cc:82:21: error: too many decimal points in number 82 | foreach (i; 0..n) { | ^~~~ a.cc:112:21: error: too many decimal points in number 112 | foreach (i; 0..n) { | ^~~~ a.cc:128:21: error: too many decimal points in number 128 | foreach (i; 0..n) { | ^~~~ a.cc:152:21: error: too many decimal points in number 152 | foreach (i; 0..n) { | ^~~~ a.cc:282:21: error: too many decimal points in number 282 | foreach (i; 0..n) { | ^~~~ a.cc:1:1: error: expected unqualified-id before '/' token 1 | /+ dub.sdl: | ^ a.cc:7:1: error: 'import' does not name a type 7 | import std.typecons, std.math; | ^~~~~~ a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:11:1: error: 'alias' does not name a type 11 | alias E = Tuple!(int, "to"); | ^~~~~ a.cc:13:12: error: 'E' was not declared in this scope 13 | long solve(E[][] g) { | ^ a.cc:13:14: error: expected primary-expression before ']' token 13 | long solve(E[][] g) { | ^ a.cc:13:16: error: expected primary-expression before ']' token 13 | long solve(E[][] g) { | ^ a.cc: In function 'int main()': a.cc:37:19: error: expected type-specifier before 'Scanner' 37 | auto sc = new Scanner(stdin); | ^~~~~~~ a.cc:40:5: error: 'E' was not declared in this scope 40 | E[][] g = new E[][n]; | ^ a.cc:40:7: error: expected primary-expression before ']' token 40 | E[][] g = new E[][n]; | ^ a.cc:40:9: error: expected primary-expression before ']' token 40 | E[][] g = new E[][n]; | ^ a.cc:41:14: error: 'i' was not declared in this scope 41 | foreach (i; 0..m) { | ^ a.cc:48:9: error: 'writeln' was not declared in this scope 48 | writeln(0); | ^~~~~~~ a.cc:53:23: error: 'g' was not declared in this scope 53 | writeln(solve(g)); | ^ a.cc:53:24: error: 'solve' cannot be used as a function 53 | writeln(solve(g)); | ^ a.cc:53:9: error: 'writeln' was not declared in this scope 53 | writeln(solve(g)); | ^~~~~~~ a.cc: At global scope: a.cc:64:9: error: expected unqualified-id before '[' token 64 | bool[] isCycle; | ^ a.cc:65:8: error: expected unqualified-id before '[' token 65 | int[][] cycles; | ^ a.cc:66:8: error: expected unqualified-id before '[' token 66 | int[] root; | ^ a.cc:67:5: error: expected unqualified-id before 'this' 67 | this(int n) { | ^~~~ a.cc:73:8: error: expected initializer before 'namori' 73 | Namori namori(T)(T g) { | ^~~~~~ a.cc:120:29: error: expected ',' or '...' before 'g' 120 | Namori directedNamori(int[] g) { | ^ a.cc: In function 'Namori directedNamori(int*)': a.cc:121:5: error: 'import' was not declared in this scope 121 | import std.algorithm : find, each; | ^~~~~~ a.cc:122:11: error: expected ';' before 'std' 122 | import std.range; | ^~~~ | ; a.cc:123:11: error: expected ';' before 'std' 123 | import std.conv : to; | ^~~~ | ; a.cc:124:13: error: 'g' was not declared in this scope 124 | int n = g.length.to!int; | ^ a.cc:125:24: error: no matching function for call to 'Namori::Namori(int&)' 125 | auto nmr = Namori(n); | ^ a.cc:63:8: note: candidate: 'constexpr Namori::Namori()' 63 | struct Namori { | ^~~~~~ a.cc:63:8: note: candidate expects 0 arguments, 1 provided a.cc:63:8: note: candidate: 'constexpr Namori::Namori(const Namori&)' a.cc:63:8: note: no known conversion for argument 1 from 'int' to 'const Namori&' a.cc:63:8: note: candidate: 'constexpr Namori::Namori(Namori&&)' a.cc:63:8: note: no known conversion for argument 1 from 'int' to 'Namori&&' a.cc:126:5: error: 'with' was not declared in this scope 126 | with (nmr) { | ^~~~ a.cc: At global scope: a.cc:162:5: error: 'import' does not name a type 162 | import std.stdio : File; | ^~~~~~ a.cc:162:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:163:5: error: 'import' does not name a type 163 | import std.conv : to; | ^~~~~~ a.cc:163:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:164:5: error: 'import' does not name a type 164 | import std.range : front, popFront, array, ElementType; | ^~~~~~ a.cc:164:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:165:5: error: 'import' does not name a type 165 | import std.array : split; | ^~~~~~ a.cc:165:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:166:5: error: 'import' does not name a type 166 | import std.traits : isSomeChar, isStaticArray, isArray; | ^~~~~~ a.cc:166:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:167:5: error: 'import' does not name a type 167 | import std.algorithm : map; | ^~~~~~ a.cc:167:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:168:5: error: 'File' does not name a type 168 | File f; | ^~~~ a.cc:169:5: error: expected unqualified-id before 'this' 169 | this(File f) { | ^~~~ a.cc:172:5: error: 'string' does not name a type 172 | string[] buf; | ^~~~~~ a.cc:173:12: error: expected ':' before 'bool' 173 | private bool succ() { | ^~~~~ | : a.cc:180:12: error: expected ':' before 'bool' 180 | private bool readSingle(T)(ref T x) { | ^~~~~ | : a.cc:180:29: error: 'T' has not been declared 180 | private bool readSingle(T)(ref T x) { | ^ a.cc:180:32: error: 'ref' has not been declared 180 | private bool readSingle(T)(ref T x) { | ^~~ a.cc:180:38: error: expected ',' or '...' before 'x' 180 | private bool readSingle(T)(ref T x) { | ^ a.cc:180:13: error: 'readSingle' declared as function returning a function 180 | private bool readSingle(T)(ref T x) { | ^~~~ a.cc:202:14: error: 'T' has not been declared 202 | int read(T, Args...)(ref T x, auto ref Args args) { | ^ a.cc:202:17: error: 'Args' has not been declared 202 | int read(T, Args...)(ref T x, auto ref Args args) { | ^~~~ a.cc:202:26: error: 'ref' has not been declared 202 | int read(T, Args...)(ref T x, auto ref Args args) { | ^~~ a.cc:202:32: error: expected ',' or '...' before 'x' 202 | int read(T, Args...)(ref T x, auto ref Args args) { | ^ a.cc:202:5: error: 'read' declared as function returning a function 202 | int read(T, Args...)(ref T x, auto ref Args args) { | ^~~ a.cc: In member function 'bool Scanner::succ()': a.cc:174:17: error: 'buf' was not declared in this scope 174 | while (!buf.length) { | ^~~ a.cc:175:17: error: 'f' was not declared in this scope 175 | if (f.eof) return false; | ^ a.cc:176:19: error: 'f' was not declared in this scope 176 | buf = f.readln.split; | ^ a.cc: At global scope: a.cc:213:5: error: 'import' was not declared in this scope 213 | import std.path : buildPath; | ^~~~~~ a.cc:213:12: error: expected '}' before 'std' 213 | import std.path : buildPath; | ^~~ a.cc:212:10: note: to match this '{' 212 | unittest { | ^ a.cc:213:12: error: expected ',' or ';' before 'std' 213 | import std.path : buildPath; | ^~~ a.cc:214:5: error: 'import' does not name a type 214 | import std.file : tempDir; | ^~~~~~ a.cc:214:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:215:5: error: 'import' does not name a type 215 | import std.algorithm : equal; | ^~~~~~ a.cc:215:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:216:5: error: 'import' does not name a type 216 | import std.stdio : File; | ^~~~~~ a.cc:216:5: note: C++20 'import' only available with '-fmodules-ts' a.cc:217:5: error: 'string' does not name a type 217 | string fileName = buildPath(tempDir, "kyuridenanmaida.txt"); | ^~~~~~ a.cc:218:22: error: 'fileName' was not declared in this scope 218 | auto fout = File(fileName, "w"); | ^~~~~~~~ a.cc:218:17: error: 'File' was not declared in this scope 218 | auto fout = File(fileName, "w"); | ^~~~ a.cc:219:5: error: 'fout' does not name a type 219 | fout.writeln("1 2 3"); | ^~~~ a.cc:220:5: error: 'fout' does not name a type 220 | fout.writeln("ab cde"); | ^~~~ a.cc:221:5: error: 'fout' does not name a type 221 | fout.writeln("1.0 1.0 2.0"); | ^~~~ a.cc:222:5: error: 'fout' does not name a type 222 | fout.close; | ^~~~ a.cc:223:35: error: 'fileName' was not declared in this scope 223 | Scanner sc = new Scanner(File(fileName, "r")); | ^~~~~~~~ a.cc:223:30: error: 'File' was not declared in this scope 223 | Scanner sc = new Scanner(File(fileName, "r")); | ^~~~ a.cc:225:9: error: expected identifier before numeric constant 225 | int[2] b; | ^ a.cc:225:9: error: expected ']' before numeric constant 225 | int[2] b; | ^ | ] a.cc:225:8: error: structured binding declaration cannot have type 'int' 225 | int[2] b; |
s538307757
p04010
C++
#define DEB #include<bits/stdc++.h> #define REP(i,m) for(int i=0;i<(m);++i) #define REPN(i,m,in) for(int i=(in);i<(m);++i) #define ALL(t) (t).begin(),(t).end() #define CLR(a) memset((a),0,sizeof(a)) #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; #ifdef DEB #define dump(x) cerr << #x << " = " << (x) << endl #define prl cerr<<"called:"<< __LINE__<<endl #define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;} #else #define dump(x) ; #define dumpR(x) ; #define dumpY(x) ; #define dumpG(x) ; #define prl ; template<class T> void debug(T a,T b){ ;} #endif template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; } template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; } typedef long long int lint; typedef pair<int,int> pi; namespace std{ template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.fr<<','<<a.sc<<')'; return out; } } //const int INF=5e8; int n,m; vector<int> g[100005]; void ng(){ puts("-1"); exit(0); } pi dfs(int v,int p){ if(g[v].empty()) return mp(1,1); for(auto to:g[v]){ if(to==p) continue; pi nxt=dfs(to,v); cost+=nxt.fr; sign^=nxt.sc; } if(sign==0) return mp(cost+1,1); else return mp(cost,0); } void solve1(){ REP(i,n-1){ int a,b;scanf("%d%d",&a,&b);--a;--b; g[a].pb(b); g[b].pb(a); } pi res=dfs(0,-1); if(res.sc==1) ng(); printf("%d\n",res.fr); } int main(){ cin>>n>>m; if(n&1) ng(); if(m==n-1) solve1(); return 0; }
a.cc: In function 'pi dfs(int, int)': a.cc:57:5: error: 'cost' was not declared in this scope; did you mean 'cosl'? 57 | cost+=nxt.fr; | ^~~~ | cosl a.cc:58:5: error: 'sign' was not declared in this scope; did you mean 'sin'? 58 | sign^=nxt.sc; | ^~~~ | sin a.cc:60:6: error: 'sign' was not declared in this scope; did you mean 'sin'? 60 | if(sign==0) return mp(cost+1,1); | ^~~~ | sin a.cc:60:25: error: 'cost' was not declared in this scope; did you mean 'cosl'? 60 | if(sign==0) return mp(cost+1,1); | ^~~~ | cosl a.cc:61:18: error: 'cost' was not declared in this scope; did you mean 'cosl'? 61 | else return mp(cost,0); | ^~~~ | cosl
s116212536
p04010
C++
#include <iostream> #include <fstream> #include <vector> #include <stack> #include <queue> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <map> #include <set> using namespace std; typedef long long ll; typedef pair<int,int> PP; /* freopen("input","r",stdin); freopen("output","w",stdout); */ int N, M; vector<unordered_set<int> > G; vector<vector<int> > T; ll res; void build(int a, int b) { unordered_set<int>::iterator it; for (it = G[a].begin();it != G[a].end();++it) { int c = *it; if (c == b) continue; T[a].push_back(c); build(c, a); } return; } int cal(int a) { int now = 1; // Need one A. for (int i = 0;i < T[a].size();i++) { now -= cal(T[a][i]); } if (a != 1) { res += abs(now); } return now; } int main() { ios::sync_with_stdio(false); cin >> N >> M; G.resize(N + 1); int a, b; for (int i = 0;i < M;i++) { cin >> a >> b; G[a].insert(b); G[b].insert(a); } if (N == M) { res = 0; queue<int> X; for (int i = 1;i <= N;i++) { if (G[i].size() == 1) X.push(i); } int need[100010]; for (int i = 1;i <= N;i++) need[i] = 1; while (X.size() > 0) { a = X.front(); X.pop(); unordered_set<int>::iterator it; it = G[a].begin(); b = *it; res += abs(need[a]); need[b] -= need[a]; G[b].erase(a); if (G[b].size() == 1) X.push(b); } int start = -1; for (int i = 1;i <= N;i++) { if (G[i].size() == 2) { start = i; break; } } vector<ll> route; route.push_back(start); unordered_set<int>::iterator it; it = G[start].begin(); int pre = start; int crt = *it; while (crt != start) { route.push_back(crt); it = G[crt].begin(); if (*it == pre) it++; pre = crt; crt = *it; } // Let it go! vector<ll> cost, pos, neg, all; int zero = 0; for (int i = 0;i < route.size() - 1;i++) { res += abs(need[route[i]]); cost.push_back(need[route[i]]); need[route[i + 1]] -= need[route[i]]; } // No solution. if (need[route[route.size() - 1]] % 2 != 0) { cout << -1 << endl; return 0; } // Make inverse flow. ll rem = need[route[route.size() - 1]] / 2; for (int i = 0;i < cost.size();i++) { res -= abs(cost[i]) - abs(cost[i] - rem); cost[i] -= rem; rem *= -1; } res += abs(rem); cost.push_back(-rem); if (route.size() % 2) { cout << res << endl; return 0; } for (int i = 0;i < cost.size();i++) { if (i % 2 == 0) { if (cost[i] > 0) pos.push_back(cost[i]); else if (cost[i] < 0) neg.push_back(cost[i]); else zero++; } else { if (cost[i] > 0) neg.push_back(-cost[i]); else if (cost[i] < 0) pos.push_back(-cost[i]); else zero++; } all.push_back(abs(cost[i])); } sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end()); for (int i = 0; i * 2 < neg.size();i++) { swap(neg[i], neg[neg.size() - 1 - i]); } sort(all.begin(), all.end()); ll num = all[all.size() / 2]; for (int i = 0;i < pos.size();i++) { res -= abs[pos[i]] - abs(pos[i] - num); } for (int i = 0;i < neg.size();i++) { res -= abs[neg[i]] - abs(neg[i] + num); } res += zero * num; cout << res << endl; return 0; } else { T.resize(N + 1); build(1, 0); res = 0; int ok = cal(1); if (ok != 0) cout << -1 << endl; else cout << res << endl; } return 0; }
a.cc: In function 'int main()': a.cc:152:23: error: invalid types '<unresolved overloaded function type>[__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}]' for array subscript 152 | res -= abs[pos[i]] - abs(pos[i] - num); | ^ a.cc:155:23: error: invalid types '<unresolved overloaded function type>[__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}]' for array subscript 155 | res -= abs[neg[i]] - abs(neg[i] + num); | ^
s814996789
p04010
C++
#include <iostream> #include <fstream> #include <vector> #include <stack> #include <queue> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <map> #include <set> using namespace std; typedef long long ll; typedef pair<int,int> PP; /* freopen("input","r",stdin); freopen("output","w",stdout); */ int N, M; vector<unordered_set<int> > G; vector<vector<int> > T; ll res; void build(int a, int b) { unordered_set<int>::iterator it; for (it = G[a].begin();it != G[a].end();++it) { int c = *it; if (c == b) continue; T[a].push_back(c); build(c, a); } return; } int cal(int a) { int now = 1; // Need one A. for (int i = 0;i < T[a].size();i++) { now -= cal(T[a][i]); } if (a != 1) { res += abs(now); } return now; } int main() { ios::sync_with_stdio(false); cin >> N >> M; G.resize(N + 1); int a, b; for (int i = 0;i < M;i++) { cin >> a >> b; G[a].insert(b); G[b].insert(a); } if (N == M) { res = 0; queue<int> X; for (int i = 1;i <= N;i++) { if (G[i].size() == 1) X.push(i); } int need[100010]; for (int i = 1;i <= N;i++) need[i] = 1; while (X.size() > 0) { a = X.front(); X.pop(); unordered_set<int>::iterator it; it = G[a].begin(); b = *it; res += abs(need[a]); need[b] -= need[a]; G[b].erase(a); if (G[b].size() == 1) X.push(b); } int start = -1; for (int i = 1;i <= N;i++) { if (G[i].size() == 2) { start = i; break; } } vector<ll> route; route.push_back(start); unordered_set<int>::iterator it; it = G[start].begin(); int pre = start; int crt = *it; while (crt != start) { route.push_back(crt); it = G[crt].begin(); if (*it == pre) it++; pre = crt; crt = *it; } // Let it go! vector<ll> cost, pos, neg, all; int zero = 0; for (int i = 0;i < route.size() - 1;i++) { res += abs(need[route[i]]); cost.push_back(need[route[i]]); need[route[i + 1]] -= need[route[i]]; } // No solution. if (need[route[route.size() - 1]] % 2 != 0) { cout << -1 << endl; return 0; } // Make inverse flow. ll rem = need[route[route.size() - 1]] / 2; for (int i = 0;i < cost.size();i++) { res -= abs(cost[i]) - abs(cost[i] - rem); cost[i] -= rem; rem *= -1; } res += abs(rem); cost.push_back(-rem); if (route.size() % 2) { cout << res << endl; return 0; } for (int i = 0;i < cost.size();i++) { if (i % 2 == 0) { if (cost[i] > 0) pos.push_back(cost[i]); else if (cost[i] < 0) neg.push_back(cost[i]); else zero++; } else { if (cost[i] > 0) neg.push_back(-cost[i]); else if (cost[i] < 0) pos.push_back(-cost[i]); else zero++; } if (cost[i] != 0) all.push_back(abs(cost[i])); } sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end()); for (int i = 0; i * 2 < neg.size();i++) { swap(neg[i], neg[neg.size() - 1 - i]); } if (pos.size() + zero <= neg.size() && neg.size() + zero <= pos.size()) { cout << res << endl; return 0; } sort(all.begin(), all.end()); if (zero.size() > all.size()) { cout << res << endl; return 0; } int idx = all.size() - zero.size(); ll num = all[idx]; for (int i = 0;i < pos.size();i++) { res -= abs(pos[i]) - abs(pos[i] - num); } for (int i = 0;i < neg.size();i++) { res -= abs(neg[i]) - abs(neg[i] + num); } res += zero * num; cout << res << endl; return 0; } else { T.resize(N + 1); build(1, 0); res = 0; int ok = cal(1); if (ok != 0) cout << -1 << endl; else cout << res << endl; } return 0; }
a.cc: In function 'int main()': a.cc:154:18: error: request for member 'size' in 'zero', which is of non-class type 'int' 154 | if (zero.size() > all.size()) { | ^~~~ a.cc:158:37: error: request for member 'size' in 'zero', which is of non-class type 'int' 158 | int idx = all.size() - zero.size(); | ^~~~
s862768919
p04010
C++
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int inf = 1e9+7; int n, m, f[N][2]; vector<int> g[N]; void dfs(int v, int pr = -1) { f[v][0] = 0; f[v][1] = inf; for (auto& to : g[v]) { if (to == pr) continue; dfs(to, v); int b[2] = {f[v][0], f[v][1]}; f[v][0] = f[v][1] = inf; f[v][1] = min(f[v][1], b[0] + f[to][0] + 1); f[v][1] = min(f[v][1], b[1] + f[to][1]); f[v][0] = min(f[v][0], b[0] + f[to][1]); } } } int main() { scanf("%d %d", &n, &m); if (n == m) { return 0; } for (int i = 0; i < m; ++i) { int x, y; scanf("%d %d", &x, &y); --x; --y; g[x].push_back(y); g[y].push_back(x); } dfs(0); cout << (f[0][1] == inf ? -1 : f[0][1]) << endl; return 0; }
a.cc:23:1: error: expected declaration before '}' token 23 | } | ^
s677081015
p04010
C++
#include <bits/stdc++.h> #include<iostream> #include<cstdio> #include<vector> #include<queue> #include<map> #include<cstring> #include<string> #include <math.h> #include<algorithm> #include<functional> #define int long long #define inf 1000000007 #define pa pair<int,int> // #define ll long long #define pal pair<ll,ll> #define ppa pair<pa,pa> #define mp make_pair #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b))<EPS) using namespace std; class Point{ public: double x,y; Point(double x=0,double y=0):x(x),y(y) {} Point operator + (Point p) {return Point(x+p.x,y+p.y);} Point operator - (Point p) {return Point(x-p.x,y-p.y);} Point operator * (double a) {return Point(x*a,y*a);} Point operator / (double a) {return Point(x/a,y/a);} double absv() {return sqrt(norm());} double norm() {return x*x+y*y;} bool operator < (const Point &p) const{ return x != p.x ? x<p.x: y<p.y; } bool operator == (const Point &p) const{ return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS; } }; typedef Point Vector; struct Segment{ Point p1,p2; }; double hen(Vector a){ if(fabs(a.x)<EPS && a.y>0) return acos(0); else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0); else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0); else if(fabs(a.y)<EPS && a.x>0) return 0.0; else if(a.y>0) return acos(a.x/a.absv()); else return 2*acos(0)+acos(-a.x/a.absv()); } double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; } double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; //----------------kokomade temple------------ vector<int> G[100030]; int n,k; int a[100020]; int ra[100020]; int sumi[100020]={0}; int N=262144; pa sgt[530000]; pa minis(int i,int j ){ if(i==j) return sgt[i]; else if(i%2==1){ pa z=minis(i+1,j); if(sgt[i].first<z.first)return sgt[i] ; else return z; } else if(j%2==0) { pa z=minis(i,j-1); if(sgt[j].first<z.first)return sgt[j] ; else return z; } else return minis(i/2,j/2); } pa sgtmin(int i ,int j){ return minis(i+N,j+N); } void upd(int x,int y){ x+=N; sgt[x].first=y; sgt[x].second=x; x=x/2; while(x != 0){ if(sgt[2*x+1].first<sgt[2*x].first){ sgt[x]=sgt[2*x+1]; } else sgt[x]=sgt[2*x]; x=x/2; } } void saiki(int i){ int y=G[i].size(); for(int j=0;j<y;j++){ ra[G[i][j]] = ra[i]+1; saiki(G[i][j]); } } void sai0(int i){ sumi[i]=1; // cout<<"sai"<<" "<<i<<endl; upd(i,0); ra[i]=0; int y=G[i].size(); for(int j=0;j<y;j++){ if(sumi[G[i][j]]==1) continue; // ra[G[i][j]] =0; // upd(G[i][j],0); sai0(G[i][j]); // sumi[G[i][j]]=1; } } signed main(){ cin>>n; if(n%2==0) cout<<-1<<endl; else cout<n-1<<endl; return 0; }
a.cc: In function 'int main()': a.cc:141:22: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator<<' 141 | else cout<n-1<<endl; | ~~~^~~~~~
s157104958
p04011
C++
#include <bits/stdc++.h> using namespace std; int main() { int N,K,X,Y; cin >> N >> K >> X >> Y; if(N<K){ cout << X*K << endl; } else {cout << X*K+(N-K)*Y << endl; }
a.cc: In function 'int main()': a.cc:12:2: error: expected '}' at end of input 12 | } | ^ a.cc:4:12: note: to match this '{' 4 | int main() { | ^
s032547616
p04011
C++
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N >> K >> X >> Y; if(N<K){ cout << X*K << endl; } else {cout << X*K+(N-K)*Y << endl; }
a.cc: In function 'int main()': a.cc:6:14: error: 'K' was not declared in this scope 6 | cin >> N >> K >> X >> Y; | ^ a.cc:6:19: error: 'X' was not declared in this scope 6 | cin >> N >> K >> X >> Y; | ^ a.cc:6:24: error: 'Y' was not declared in this scope 6 | cin >> N >> K >> X >> Y; | ^ a.cc:12:2: error: expected '}' at end of input 12 | } | ^ a.cc:4:12: note: to match this '{' 4 | int main() { | ^
s405245652
p04011
C
#include <bits/stdc++.h> using namespace std; int main() { int n,k,x,y,c=0; cin >> n >> k >> x >> y; c = k * x + (n - k) * y; cout << c; }
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory 1 | #include <bits/stdc++.h> | ^~~~~~~~~~~~~~~ compilation terminated.
s593820103
p04011
C++
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0; i < n; i++) #define REP(i, n) for(ll i = 1; i < n + 1; i++) #define PI 3.14159265359 #define EPS 0.0000000001 #define MOD 1000000007 //cout << std::fixed << std::setprecision(15) << y << endl; int main(){ ll N, K, X, Y; cin >> N >> K >> X >> Y; cout << min(N, K) * X + max(0, N - K) * Y << endl; return 0; }
a.cc: In function 'int main()': a.cc:29:32: error: no matching function for call to 'max(int, ll)' 29 | cout << min(N, K) * X + max(0, N - K) * Y << endl; | ~~~^~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, 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:29:32: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'}) 29 | cout << min(N, K) * X + max(0, N - K) * Y << endl; | ~~~^~~~~~~~~~ /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:29:32: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 29 | cout << min(N, K) * X + max(0, N - K) * Y << endl; | ~~~^~~~~~~~~~
s694055406
p04011
C++
#include <bits/stdc++.h> using namespace std; int main(){ int n,k,x,y; cin >> n >> k >> x >> y; if(n<=k) cout << n*x; else cout << k*x + (n-k)*y; return; }
a.cc: In function 'int main()': a.cc:9:3: error: return-statement with no value, in function returning 'int' [-fpermissive] 9 | return; | ^~~~~~
s775732807
p04011
C++
#include <iostream> #include <string.h> using namespace std; string c; int ara[26] = {},j; cin>>c; int len = c.size(); for(int i = 0; i< len; i++) { //j = 0; //j = c[i] - 'a'; ara[c[i]]++; } // cout<<ara[j]<<endl; bool ok = true; for(int j = 0; j<26; j++) { if(ara[j]%2!=0) ok = false; } //cout<<ok<<endl; if(ok == true ) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
a.cc:7:5: error: 'cin' does not name a type 7 | cin>>c; | ^~~ a.cc:9:5: error: expected unqualified-id before 'for' 9 | for(int i = 0; i< len; i++) | ^~~ a.cc:9:20: error: 'i' does not name a type 9 | for(int i = 0; i< len; i++) | ^ a.cc:9:28: error: 'i' does not name a type 9 | for(int i = 0; i< len; i++) | ^ a.cc:17:5: error: expected unqualified-id before 'for' 17 | for(int j = 0; j<26; j++) | ^~~ a.cc:17:20: error: 'j' does not name a type 17 | for(int j = 0; j<26; j++) | ^ a.cc:17:26: error: 'j' does not name a type 17 | for(int j = 0; j<26; j++) | ^ a.cc:23:5: error: expected unqualified-id before 'if' 23 | if(ok == true ) | ^~ a.cc:25:5: error: expected unqualified-id before 'else' 25 | else | ^~~~ a.cc:28:5: error: expected unqualified-id before 'return' 28 | return 0; | ^~~~~~ a.cc:29:1: error: expected declaration before '}' token 29 | } | ^
s962817328
p04011
C++
else if(a==5&&b==5&&c==7) cout << YES;
a.cc:1:1: error: expected unqualified-id before 'else' 1 | else if(a==5&&b==5&&c==7) cout << YES; | ^~~~
s475477921
p04011
Java
public class Abc_044 { public static void main(String args[]) { int N=5; int K=3; int X=10000; int Y=9000; int yen; yen= K*X+(N-K)*Y; System.out.println(yen); } }
Main.java:1: error: class Abc_044 is public, should be declared in a file named Abc_044.java public class Abc_044 { ^ 1 error
s349449876
p04011
Java
public class Abc_044 { public static void main(String args[]) { int N; int K; int X; int Y; int yen; yen= K*X+(N-K)*Y; System.out.println(yen); } }
Main.java:1: error: class Abc_044 is public, should be declared in a file named Abc_044.java public class Abc_044 { ^ 1 error
s854259678
p04011
C
#include <stdio.h> int main(void){ int N,K,X,Y,total; scanf("%d%d%d%d",&N,&K,&X,&Y); total=(K*X)+(N-K)*Y; printf("%d\n",total) return 0; }
main.c: In function 'main': main.c:9:29: error: expected ';' before 'return' 9 | printf("%d\n",total) | ^ | ; 10 | return 0; | ~~~~~~
s257451052
p04011
C
#include <stdio.h> int main(void){ int N,K,X,Y,total; scanf("%d%d%d%d",&N,&K,&X,%Y); total=(K*X)+(N-K)*Y; printf("%d\n",total) return 0; }
main.c: In function 'main': main.c:6:35: error: expected expression before '%' token 6 | scanf("%d%d%d%d",&N,&K,&X,%Y); | ^ main.c:9:29: error: expected ';' before 'return' 9 | printf("%d\n",total) | ^ | ; 10 | return 0; | ~~~~~~