Submission #874640

#TimeUsernameProblemLanguageResultExecution timeMemory
874640tvladm2009Mergers (JOI19_mergers)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define eb emplace_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef basic_string<int> BI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=500000; const int LOG=20; int n,k; int s[N]; VI e[N]; int up[LOG][N],dep[N],node[N]; VI t[N]; void dfs(int u,int par=0) { dep[u]=dep[par]+1; up[0][u]=par; for (auto v:e[u]) { if (v != par) dfs(v, u); } } int lca(int a,int b) { if (dep[a]<dep[b]) swap(a,b); per(i,LOG,0) if (dep[a]-(1<<i)>=dep[b]) a=up[i][a]; if (a==b) return a; per(i,LOG,0) if (up[i][a]!=up[i][b]) a=up[i][a],b=up[i][b]; return up[0][a]; } int dfs2(int u,int par=0) { int mnlvl=dep[node[s[i]]]; for (auto v:e[u]) { if (v!=par) mnlvl=min(mnlvl,dfs2(v,u)); } if(mn>=dp[u]) bad[u]=par; return mn; } int x=0; int id[N]; void dfs3(int u,int par=0) { if (bad[u]==par) { id[u]=++id; } else { id[u]=id[par]; } for (auto v:e[u]) { if (v != par) dfs3(v, u); } } void dfs4(int u,int par=0) { ; } int main() { scanf("%d%d",&n,&k); rep(i,1,n) { int u,v; scanf("%d%d",&u,&v); e[u].pb(v); e[v].pb(u); } rep(i,1,n+1) scanf("%d",&s[i]); dfs(1); rep(i,1,LOG) rep(j,1,n+1) up[i][j]=up[i-1][up[i-1][j]]; rep(i,1,n+1) { if(node[s[i]]==0) node[s[i]]=i; else node[s[i]]=lca(node[s[i]],i); } dfs2(1); dfs3(1); dfs4(1); int leaves=0; rep(i,1,k+1) { sort(t[i].begin(),t[i].end()); t[i].resize(unique(t[i].begin(),t[i].end())-t[i].begin()); if(t[i].size()==1) leaves++; } printf("%d\n",(leaves+1)/2); }

Compilation message (stderr)

mergers.cpp: In function 'int dfs2(int, int)':
mergers.cpp:49:26: error: 'i' was not declared in this scope
   49 |     int mnlvl=dep[node[s[i]]];
      |                          ^
mergers.cpp:53:8: error: 'mn' was not declared in this scope; did you mean 'n'?
   53 |     if(mn>=dp[u]) bad[u]=par;
      |        ^~
      |        n
mergers.cpp:53:12: error: 'dp' was not declared in this scope; did you mean 'dep'?
   53 |     if(mn>=dp[u]) bad[u]=par;
      |            ^~
      |            dep
mergers.cpp:53:19: error: 'bad' was not declared in this scope
   53 |     if(mn>=dp[u]) bad[u]=par;
      |                   ^~~
mergers.cpp:54:12: error: 'mn' was not declared in this scope; did you mean 'n'?
   54 |     return mn;
      |            ^~
      |            n
mergers.cpp: In function 'void dfs3(int, int)':
mergers.cpp:61:9: error: 'bad' was not declared in this scope
   61 |     if (bad[u]==par) {
      |         ^~~
mergers.cpp:62:17: error: lvalue required as increment operand
   62 |         id[u]=++id;
      |                 ^~
mergers.cpp: In function 'int main()':
mergers.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
mergers.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         scanf("%d%d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~
mergers.cpp:83:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     rep(i,1,n+1) scanf("%d",&s[i]);
      |                  ~~~~~^~~~~~~~~~~~