답안 #128838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128838 2019-07-11T10:08:03 Z sealnot123 Mergers (JOI19_mergers) C++14
0 / 100
101 ms 31664 KB
#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

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]);
                    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23804 KB Output is correct
8 Correct 24 ms 23804 KB Output is correct
9 Incorrect 24 ms 23800 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23804 KB Output is correct
8 Correct 24 ms 23804 KB Output is correct
9 Incorrect 24 ms 23800 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23804 KB Output is correct
8 Correct 24 ms 23804 KB Output is correct
9 Incorrect 24 ms 23800 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 27272 KB Output is correct
2 Correct 101 ms 31664 KB Output is correct
3 Incorrect 26 ms 23968 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 24 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23804 KB Output is correct
8 Correct 24 ms 23804 KB Output is correct
9 Incorrect 24 ms 23800 KB Output isn't correct
10 Halted 0 ms 0 KB -