Submission #962875

#TimeUsernameProblemLanguageResultExecution timeMemory
962875biximoStations (IOI20_stations)Java
Compilation error
0 ms0 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define N 1005 vector<int> adj[N]; int n, ids[N], sz[N], id; void dfs(int c, int pr) { ids[c] = id++; sz[c] = 1; for(int i: adj[c]) { if(i == pr) continue; dfs(i, c); sz[c] += sz[i]; } } vector<int> euler_tree() { id = 0; dfs(0, -1); vector<int> ans(n); for(int i = 0; i < n; i ++) { sz[i] --; ans[i] = ids[i]*1000+sz[i]; } return ans; } vector<int> nddds; void DFS(int c, int pr) { nddds.push_back(c); for(int i: adj[c]) { if(i == pr) continue; DFS(i, c); } } vector<int> flatten() { nddds.clear(); for(int i = 0; i < n; i ++) { if(adj[i].size() == 1) { DFS(i, -1); vector<int> nds = nddds; vector<int> ans(n); for(int j = 0; j < n; j ++) { ans[nds[j]] = j; } return ans; } } return vector<int>(); assert(0); } std::vector<int> label(int ngb, int k, std::vector<int> u, std::vector<int> v) { n = ngb; for(auto&i: adj) i.clear(); for(int i = 0; i < n-1; i ++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } int ms = 0; for(auto&i: adj) ms = max(ms, (int)i.size()); if(k >= 1000000) { return euler_tree(); } for(int i = 0; i < n-1; i ++) { if(u[i] == i+1 && v[i] == i/2 || u[i] == i/2 && v[i] == i+1) continue; return flatten(); } vector<int> nds; for(int i = 0; i < n; i ++) nds.push_back(i); return nds; } struct Nd { int id, sz; Nd(int i) : id(i/1000), sz(i%1000) { } }; int findEuler(int s, int t, vector<int> c) { int sid = s/1000, ssz = s%1000; int tid = t/1000, tsz = t%1000; if(sid <= tid && tid <= sid + ssz) { for(int i: c) { int nid = i/1000, isz = i%1000; if(nid <= tid && tid <= nid + nsz) { return i; } } assert(0); } for(int i: c) { int nsz = i%1000; if(nsz >= ssz) { return i; } } assert(0); } int findFlat(int s, int t, vector<int> c) { if(s < t) { if(c.size() == 1) return c[0]; return c[1]; } else { return c[0]; } } int ds[N], pr[N]; int findWeird(int s, int t, vector<int> c) { for(auto&i: adj) i.clear(); for(int i = 0; i < max(s,t); i ++) { adj[i+1].push_back(i/2); adj[i/2].push_back(i+1); } for(auto&i: ds) i = N; queue<int> que; que.push(t); ds[t] = 0; pr[t] = 0; while(que.size()) { int c = que.front(); que.pop(); for(int i: adj[c]) { if(ds[i] > ds[c]+1) { ds[i] = ds[c]+1; pr[i] = c; que.push(i); } } } return pr[s]; } int find_next_station(int s, int t, std::vector<int> c) { int mv = max(s, t); for(int i: c) mv = max(mv, i); if(mv >= 1000) { return findEuler(s,t,c); } if(c.size() == 1 && (c[0] == s+1 || c[0] == s-1)) { return findFlat(s,t,c); } if(c.size() == 2 && c[0] == s-1 && c[1] == s+1) { return findFlat(s,t,c); } return findWeird(s,t,c); } // int main() { // int nv, nk; // cin >> nv >> nv >> nk; // vector<int> u, v; // vector<int> ptss[N]; // for(int i = 1; i < nv; i ++) { // int a, b; // cin >> a >> b; // u.push_back(a); // v.push_back(b); // ptss[a].push_back(b); // ptss[b].push_back(a); // } // vector<int> lb = label(nv, nk, u, v);; // for(int i: lb) cout << i << " "; // // int q; // // cin >> q; // // while(q--) { // // int a, b, c; // // cin >> a >> b >> c; // // vector<int> adjs; // // for(int i: ptss[a]) { // // adjs.push_back(lb[i]); // // } // // cout << find_next_station(lb[a], lb[b], adjs) << " "; // // } // }

Compilation message (stderr)

stations.java:1: error: illegal character: '#'
#include "stations.h"
^
stations.java:1: error: class, interface, or enum expected
#include "stations.h"
         ^
stations.java:2: error: illegal character: '#'
#include <bits/stdc++.h>
^
stations.java:4: error: illegal character: '#'
#define N 1005
^
stations.java:4: error: class, interface, or enum expected
#define N 1005
        ^
stations.java:6: error: class, interface, or enum expected
int n, ids[N], sz[N], id;
^
stations.java:7: error: class, interface, or enum expected
void dfs(int c, int pr) {
^
stations.java:9: error: class, interface, or enum expected
	sz[c] = 1;
	^
stations.java:10: error: class, interface, or enum expected
	for(int i: adj[c]) {
	^
stations.java:12: error: class, interface, or enum expected
		dfs(i, c);
		^
stations.java:13: error: class, interface, or enum expected
		sz[c] += sz[i];
		^
stations.java:14: error: class, interface, or enum expected
	}
	^
stations.java:18: error: class, interface, or enum expected
	dfs(0, -1);
	^
stations.java:19: error: class, interface, or enum expected
	vector<int> ans(n);
	^
stations.java:20: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) {
	^
stations.java:20: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) {
	               ^
stations.java:20: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) {
	                      ^
stations.java:22: error: class, interface, or enum expected
		ans[i] = ids[i]*1000+sz[i];
		^
stations.java:23: error: class, interface, or enum expected
	}
	^
stations.java:25: error: class, interface, or enum expected
}
^
stations.java:27: error: class, interface, or enum expected
void DFS(int c, int pr) {
^
stations.java:29: error: class, interface, or enum expected
	for(int i: adj[c]) {
	^
stations.java:31: error: class, interface, or enum expected
		DFS(i, c);
		^
stations.java:32: error: class, interface, or enum expected
	}
	^
stations.java:36: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) {
	^
stations.java:36: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) {
	               ^
stations.java:36: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) {
	                      ^
stations.java:39: error: class, interface, or enum expected
			vector<int> nds = nddds;
			^
stations.java:40: error: class, interface, or enum expected
			vector<int> ans(n);
			^
stations.java:41: error: class, interface, or enum expected
			for(int j = 0; j < n; j ++) {
			^
stations.java:41: error: class, interface, or enum expected
			for(int j = 0; j < n; j ++) {
			               ^
stations.java:41: error: class, interface, or enum expected
			for(int j = 0; j < n; j ++) {
			                      ^
stations.java:43: error: class, interface, or enum expected
			}
			^
stations.java:45: error: class, interface, or enum expected
		}
		^
stations.java:48: error: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier
	assert(0);
	^
stations.java:49: error: class, interface, or enum expected
}
^
stations.java:52: error: class, interface, or enum expected
	for(auto&i: adj) i.clear();
	^
stations.java:53: error: class, interface, or enum expected
	for(int i = 0; i < n-1; i ++) {
	^
stations.java:53: error: class, interface, or enum expected
	for(int i = 0; i < n-1; i ++) {
	               ^
stations.java:53: error: class, interface, or enum expected
	for(int i = 0; i < n-1; i ++) {
	                        ^
stations.java:55: error: class, interface, or enum expected
		adj[v[i]].push_back(u[i]);
		^
stations.java:56: error: class, interface, or enum expected
	}
	^
stations.java:58: error: class, interface, or enum expected
	for(auto&i: adj) ms = max(ms, (int)i.size());
	^
stations.java:59: error: class, interface, or enum expected
	if(k >= 1000000) {
	^
stations.java:61: error: class, interface, or enum expected
	} 
	^
stations.java:62: error: class, interface, or enum expected
	for(int i = 0; i < n-1; i ++) {
	               ^
stations.java:62: error: class, interface, or enum expected
	for(int i = 0; i < n-1; i ++) {
	                        ^
stations.java:64: error: class, interface, or enum expected
		return flatten();
		^
stations.java:65: error: class, interface, or enum expected
	}
	^
stations.java:67: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) nds.push_back(i);
	^
stations.java:67: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) nds.push_back(i);
	               ^
stations.java:67: error: class, interface, or enum expected
	for(int i = 0; i < n; i ++) nds.push_back(i);
	                      ^
stations.java:68: error: class, interface, or enum expected
	return nds;
	^
stations.java:69: error: class, interface, or enum expected
}
^
stations.java:72: error: class, interface, or enum expected
	Nd(int i) : id(i/1000), sz(i%1000) {
	^
stations.java:75: error: class, interface, or enum expected
int findEuler(int s, int t, vector<int> c) {
^
stations.java:77: error: class, interface, or enum expected
	int tid = t/1000, tsz = t%1000;
	^
stations.java:78: error: class, interface, or enum expected
	if(sid <= tid && tid <= sid + ssz) {
	^
stations.java:81: error: class, interface, or enum expected
			if(nid <= tid && tid <= nid + nsz) {
			^
stations.java:83: error: class, interface, or enum expected
			}
			^
stations.java:86: error: class, interface, or enum expected
	}
	^
stations.java:89: error: class, interface, or enum expected
		if(nsz >= ssz) {
		^
stations.java:91: error: class, interface, or enum expected
		}
		^
stations.java:94: error: class, interface, or enum expected
}
^
stations.java:98: error: class, interface, or enum expected
		return c[1];
		^
stations.java:99: error: class, interface, or enum expected
	} else {
	^
stations.java:101: error: class, interface, or enum expected
	}
	^
stations.java:104: error: class, interface, or enum expected
int findWeird(int s, int t, vector<int> c) {
^
stations.java:106: error: class, interface, or enum expected
	for(int i = 0; i < max(s,t); i ++) {
	^
stations.java:106: error: class, interface, or enum expected
	for(int i = 0; i < max(s,t); i ++) {
	               ^
stations.java:106: error: class, interface, or enum expected
	for(int i = 0; i < max(s,t); i ++) {
	                             ^
stations.java:108: error: class, interface, or enum expected
		adj[i/2].push_back(i+1);
		^
stations.java:109: error: class, interface, or enum expected
	}
	^
stations.java:111: error: class, interface, or enum expected
	queue<int> que;
	^
stations.java:112: error: class, interface, or enum expected
	que.push(t); ds[t] = 0; pr[t] = 0;
	^
stations.java:112: error: class, interface, or enum expected
	que.push(t); ds[t] = 0; pr[t] = 0;
	             ^
stations.java:112: error: class, interface, or enum expected
	que.push(t); ds[t] = 0; pr[t] = 0;
	                        ^
stations.java:113: error: class, interface, or enum expected
	while(que.size()) {
	^
stations.java:114: error: class, interface, or enum expected
		int c = que.front(); que.pop();
		                     ^
stations.java:115: error: class, interface, or enum expected
		for(int i: adj[c]) {
		^
stations.java:118: error: class, interface, or enum expected
				pr[i] = c;
				^
stations.java:119: error: class, interface, or enum expected
				que.push(i);
				^
stations.java:120: error: class, interface, or enum expected
			}
			^
stations.java:124: error: class, interface, or enum expected
}
^
stations.java:127: error: class, interface, or enum expected
	for(int i: c) mv = max(mv, i);
	^
stations.java:128: error: class, interface, or enum expected
	if(mv >= 1000) {
	^
stations.java:130: error: class, interface, or enum expected
	}
	^
stations.java:133: error: class, interface, or enum expected
	}
	^
stations.java:136: error: class, interface, or enum expected
	}
	^
stations.java:138: error: class, interface, or enum expected
}
^
90 errors