Submission #128838

#TimeUsernameProblemLanguageResultExecution timeMemory
128838sealnot123Mergers (JOI19_mergers)C++14
0 / 100
101 ms31664 KiB
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(),(a).end() #define SZ(a) (int)(a).size() using namespace std; typedef long long LL; typedef pair<LL,LL> PLL; typedef pair<int,int> PII; typedef double D; typedef long double LD; const int N = 500005; vector<int> tree[N], g[N]; int bridge; int state[N], idx[N], lowlink[N]; int n, st, t; void dfs(int u, int p){ idx[u] = lowlink[u] = ++t; int ch = 0; for(int e : g[u]){ if(e == p && !ch){ ch = 1; continue; } if(idx[e]) lowlink[u] = min(lowlink[u], idx[e]); else{ dfs(e, u); lowlink[u] = min(lowlink[u], lowlink[e]); if(lowlink[e] > idx[u]) bridge++; } } } int main(){ int i,j,k,l,a,b,c,d; scanf("%d%d",&n,&st); for(i=1;i<n;i++){ scanf("%d%d",&a,&b); if(a<b) swap(a,b); tree[a].pb(b); } for(i=1;i<=n;i++) scanf("%d",&state[i]); for(i=1;i<=n;i++){ for(int e : tree[i]){ if(state[e] != state[i]){ g[state[e]].pb(state[i]); g[state[i]].pb(state[e]); } } } dfs(1,1); printf("%d",(bridge+1)/2); return 0; } /* 5 4 1 2 2 3 3 4 3 5 1 2 1 3 4 5 4 1 2 2 3 3 4 4 5 1 2 3 4 1 2 2 1 2 1 2 */

Compilation message (stderr)

mergers.cpp: In function 'int main()':
mergers.cpp:35:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
        ^
mergers.cpp:35:10: warning: unused variable 'k' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
          ^
mergers.cpp:35:12: warning: unused variable 'l' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
            ^
mergers.cpp:35:18: warning: unused variable 'c' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
                  ^
mergers.cpp:35:20: warning: unused variable 'd' [-Wunused-variable]
  int i,j,k,l,a,b,c,d;
                    ^
mergers.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&st);
  ~~~~~^~~~~~~~~~~~~~~
mergers.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~
mergers.cpp:42:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1;i<=n;i++) scanf("%d",&state[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...
#Verdict Execution timeMemoryGrader output
Fetching results...