제출 #532065

#제출 시각아이디문제언어결과실행 시간메모리
532065amunduzbaevRobot (JOI21_ho_t4)C++17
34 / 100
857 ms86204 KiB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

const int N = 1e5 + 5;
struct node{
	int a, b, c, p;
};
map<int, vector<ar<int, 2>>> edges[N], ee[N];
map<int, int> ss[N], uu[N];
int d[N], used[N];
node e[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m; cin>>n>>m;
	for(int i=0;i<m;i++){
		node& x = e[i]; cin>>x.a>>x.b>>x.c>>x.p;
		edges[x.a][x.c].push_back({x.b, x.p});
		edges[x.b][x.c].push_back({x.a, x.p});
		ee[x.a][x.c].push_back({x.b, x.p});
		ee[x.b][x.c].push_back({x.a, x.p});
		ss[x.a][x.c] += x.p;
		ss[x.b][x.c] += x.p;
	}
	
	priority_queue<ar<int, 4>, vector<ar<int, 4>>, greater<ar<int, 4>>> q;
	q.push({0, 1, 0, 0});
	memset(d, 127, sizeof d);
	while(!q.empty()){
		int D = q.top()[0], u = q.top()[1], v = q.top()[2], c = q.top()[3]; q.pop();
		//~ cout<<D<<" "<<u<<" "<<v<<" "<<c<<endl;
		if(c < 0){ 
			c = abs(c);
			int& sum = ss[u][c];
			for(auto x : edges[u][c]){
				q.push({D + sum - x[1], x[0], u, c});
			}
		} else if(!used[u]) {
			used[u] = 1;
			d[u] = D;
			for(auto [c, v] : edges[u]){
				int& sum = ss[u][c];
				for(auto x : v){
					q.push({D, x[0], u, -c});
					if(sum == x[1]){
						q.push({D, x[0], u, c});
					} else {
						q.push({D + min(sum - x[1], x[1]), x[0], u, c});
					}
				}
			}
		}
	}
	
	if(d[n] > 1e18) cout<<-1<<"\n";
	else cout<<d[n]<<"\n";
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:34:39: warning: unused variable 'v' [-Wunused-variable]
   34 |   int D = q.top()[0], u = q.top()[1], v = q.top()[2], c = q.top()[3]; q.pop();
      |                                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...