Submission #361518

#TimeUsernameProblemLanguageResultExecution timeMemory
361518inwbearCapital City (JOI20_capital_city)C++14
0 / 100
148 ms16108 KiB
#include<bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC target ("sse4") using namespace std; #define pb push_back #define all(x) (x).begin(),(x).end() #define MEM(x,a) memset((x),a,sizeof((x))) #define F first #define S second #define imx INT_MAX const long long MOD = (long long)(1e9+7); const long long MMX = (long long)(1e18); typedef long long LL; typedef pair<int,int> pii; int n,k,a,b,t[200005],nn[200005],st,ed,arr[200005],mx[200005],ans,t1,t2; map<int,int>mp; vector<int>v[200005]; void gen(int N,int pr,int cc) { arr[cc]=t[N]; for(int i=0;i<v[N].size();i++) { if(v[N][i]!=pr) { gen(v[N][i],N,cc+1); } } return; } int main() { scanf("%d %d",&n,&k); ans=k-1; for(int i=1;i<n;i++) { scanf("%d %d",&a,&b); v[a].pb(b); v[b].pb(a); } for(int i=1;i<=n;i++) { scanf("%d",&t[i]); if(v[i].size()==0)st=i; nn[t[i]]++; } gen(st,0,1); for(int i=1;i<=n;i++) { mx[arr[i]]=i; } for(int i=1;i<=n;i++) { if(mx[arr[i]]==i) { t1=0,t2=0; mp.clear(); for(int j=i;j>ed;j--) { if(mx[arr[j]]>j) { break; } if(0==mp[arr[i]]++) { t1++; } if(nn[arr[i]]==mp[arr[i]]) { t2++; } if(t1==t2) { ans=min(ans,t1-1); break; } } } } printf("%d",ans); }

Compilation message (stderr)

capital_city.cpp: In function 'void gen(int, int, int)':
capital_city.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<v[N].size();i++)
      |                 ~^~~~~~~~~~~~
capital_city.cpp: In function 'int main()':
capital_city.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
capital_city.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
capital_city.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |         scanf("%d",&t[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...