제출 #718422

#제출 시각아이디문제언어결과실행 시간메모리
718422KalashnikovRobot (JOI21_ho_t4)C++17
0 / 100
3076 ms101280 KiB
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second using namespace std; using ll = long long; #define int ll const int N = 1e5+5 , inf = 2e9 + 7; const ll INF = 1e18 , mod = 1e9+7 , P = 6547; map<int,vector<pair<int,int>>> mp[N]; vector<array<int,3>> g[N]; map<int,int> sum[N]; void solve(int tc) { int n, m; cin >> n >> m; vector<array<int,4>> vec; for(int i = 1; i <= m; i ++) { int a, b,c, p; cin >> a >> b >> c >> p; g[a].push_back({b,c,p}); g[b].push_back({a,c,p}); mp[a][c].push_back({b, p}); mp[b][c].push_back({a , p}); sum[a][c] += p; sum[b][c] += p; } vector<map<int,int>> d(n+1); set<array<int,3>> st; d[1][0] = 0; st.insert({0, 1 , 0}); ll res = INF; while(st.size()) { array<int,3> cur = *st.begin(); st.erase(cur); int v = cur[1]; if(v == n) { res = min(res, cur[0]); continue; } for(auto pt: g[v]) { int to = pt[0]; int c = pt[1]; int p = pt[2]; if(mp[v][c].size() - (c == cur[2]) == 1) { if(d[to].count(0) == 0 || d[v][cur[2]] < d[to][0]) { st.erase({d[to][0], to, 0}); d[to][0] = d[v][cur[2]]; st.insert({d[to][0], to, 0}); } } if(d[to].count(c) == 0 || d[v][cur[2]] + p < d[to][c]) { st.erase({d[to][c], to, c}); d[to][c] = d[v][cur[2]] + p; st.insert({d[to][c], to, c}); } if(d[to].count(0) == 0 || d[v][cur[2]] + sum[v][c] - p < d[to][0]) { st.erase({d[to][0], to, 0}); d[to][0] = d[v][cur[2]] + sum[v][c] - p; st.insert({d[to][0], to, 0}); } } } if(res == INF) res = -1; cout << res; } /* */ main() { ios; int tt = 1 , tc = 0; // cin >> tt; while(tt --) { solve(++tc); } return 0; }

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

Main.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...