Submission #94919

# Submission time Handle Problem Language Result Execution time Memory
94919 2019-01-25T07:50:03 Z Retro3014 Pairs (IOI07_pairs) C++17
0 / 100
48 ms 3596 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>

#define MAX_N 1000
using namespace std;

int N, M;
struct S{
	int idx, data;
};
struct E{
	int x, y, z;
};

vector<E> e;
vector<int> gp[MAX_N+1];
vector<S> gp2[MAX_N+1];

int p[MAX_N+1][15];
int c[MAX_N+1];
int lv[MAX_N+1];
int ans;
int dp[MAX_N+1];



void dfs(int x){
	for(int i=1; i<15; i++){
		p[x][i] = p[p[x][i-1]][i-1];
	}
	for(int i=0; i<gp[x].size(); i++){
		if(c[gp[x][i]]==0){
			c[gp[x][i]] = 3 - c[x];
			p[gp[x][i]][0] = x;
			lv[gp[x][i]] = lv[x] + 1;
			dfs(gp[x][i]);
		}
	}
}

int up(int x, int y){
	int two = (1<<14);
	for(int i=14; i>=0; i--){
		if(y>=two){
			x = p[x][i];
			y-=two;
		}
		two/=2;
	}
	return x;
}

int lca(int x, int y){

}

void dfs2(int x){
	dp[x] = 0;
	for(int i=0; i<gp[x].size(); i++){
		if(gp[x][i]!=p[x][0]){
			dfs2(gp[x][i]);
			dp[x]+=dp[gp[x][i]];
		}
	}
	for(int i=0; i<gp2[x].size(); i++){
		int k = 0, pp;
		pp = up(gp2[x][i].idx, lv[gp2[x][i].idx]-lv[x]-1);
		for(int j=0; j<gp[x].size(); j++){
			if(gp[x][j]!=p[x][0] && gp[x][j]!=pp){
				k+=dp[gp[x][j]];
			}
		}
		k+=gp2[x][i].data + dp[gp2[x][i].idx];
		dp[x] = max(dp[x], k);
	}
	return;
}

int degree[MAX_N+1];

int main(){
	scanf("%d%d", &N, &M);

	for(int i=0; i<M; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if(c==0){
			degree[a]++; degree[b]++;
			gp[a].push_back(b); gp[b].push_back(a);
		}else{
			e.push_back({a, b, c});
			ans+=c;
		}
	}
	int now;
	for(int i=1; i<=N; i++){
		if(degree[i]==1){
			now = i; break;
		}
	}
	c[now] = 1;
	lv[now] = 1;
	dfs(now);	
	for(int i=0; i<e.size(); i++){
		if(c[e[i].x]==c[e[i].y]){
			if(lv[e[i].x] > lv[e[i].y]){
				int tmp = e[i].x; e[i].x = e[i].y; e[i].y = tmp;
			}
			gp2[e[i].x].push_back({e[i].y, e[i].z});
		}
	}
	dfs2(now);
	ans-=dp[now];
	printf("%d", ans);
	return 0;
}

Compilation message

pairs.cpp: In function 'void dfs(int)':
pairs.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<gp[x].size(); i++){
               ~^~~~~~~~~~~~~
pairs.cpp: In function 'int lca(int, int)':
pairs.cpp:57:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
pairs.cpp: In function 'void dfs2(int)':
pairs.cpp:61:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<gp[x].size(); i++){
               ~^~~~~~~~~~~~~
pairs.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<gp2[x].size(); i++){
               ~^~~~~~~~~~~~~~
pairs.cpp:70:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<gp[x].size(); j++){
                ~^~~~~~~~~~~~~
pairs.cpp: In function 'int main()':
pairs.cpp:106:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<e.size(); i++){
               ~^~~~~~~~~
pairs.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
pairs.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:115:13: warning: 'now' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ans-=dp[now];
       ~~~~~~^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 3596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 47 ms 3180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 3224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 3264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 3228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 40 ms 3180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 2536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2664 KB Output isn't correct
2 Halted 0 ms 0 KB -