# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
361518 | 2021-01-30T10:57:13 Z | inwbear | Capital City (JOI20_capital_city) | C++14 | 148 ms | 16108 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4972 KB | Output is correct |
2 | Correct | 4 ms | 4972 KB | Output is correct |
3 | Correct | 3 ms | 4972 KB | Output is correct |
4 | Incorrect | 3 ms | 4972 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4972 KB | Output is correct |
2 | Correct | 4 ms | 4972 KB | Output is correct |
3 | Correct | 3 ms | 4972 KB | Output is correct |
4 | Incorrect | 3 ms | 4972 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 148 ms | 16108 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4972 KB | Output is correct |
2 | Correct | 4 ms | 4972 KB | Output is correct |
3 | Correct | 3 ms | 4972 KB | Output is correct |
4 | Incorrect | 3 ms | 4972 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |