Submission #1036090

#TimeUsernameProblemLanguageResultExecution timeMemory
1036090PhongnvRobot (JOI21_ho_t4)C++14
100 / 100
305 ms120832 KiB
///hihi PhongVan cbhk64 #include <bits/stdc++.h> using namespace std; #define pb push_back #define fo(i, l, r) for(int i = l; i <= r; i++) #define foi(i, l, r) for(int i = l; i >= r; i--) #define elif else if #define el cout << endl #define pii pair<int, int> #define mx(x, y) max(x, y) #define fi first #define se second #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) #define ll long long #define pob pop_back #define bs binary_search #define m_p make_pair #define vii vector<int> #define int long long #define getbit(j, i) (j >> i) &1 #define fillchar(a,x) memset(a, x, sizeof (a)) #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const long long oo = 1e18; const int N = 6e5+5; const int MOD = 1e9+7; vector< pii > a[N]; map<int , int> mp[N]; vector< pair<int, pii>> g[N]; int dist[N]; int sum[N]; bool vis[N]; void dij(int x) { fo(i,1,N) dist[i] = oo; priority_queue< pair < int,int > , vector < pair < int ,int > > , greater < pair < int , int > > > q; dist[x] = 0; q.push(m_p(0, x)); while (!q.empty()) { auto p1 = q.top(); int W = p1.fi; int x = p1.se; q.pop(); if (vis[x]) continue; vis[x] = 1; for (auto p2 : a[x]) { int y = p2.fi; int w = p2.se; if (vis[y] || dist[y] < W + w) continue; dist[y] = W + w; q.push({W + w, y}); } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(TASK".inp","r",stdin); //freopen(TASK".out","w",stdout); int n,m,x,y,c,p; cin >> n >> m; fo(i,1,m) { cin >> x >> y >> c >> p; g[x].push_back({c, {y, p}}); g[y].push_back({c, {x, p}}); a[x].push_back({y, p}); a[y].push_back({x, p}); } int cur = n; fo(i,1,n) { sort(g[i].begin(), g[i].end()); for (auto x : g[i]) sum[x.fi] += x.se.se; for (auto x : g[i]) { if (!vis[x.fi]) { ++cur; a[i].push_back(m_p(cur,0)); } vis[x.fi] = 1; a[cur].push_back(m_p(x.se.fi, sum[x.fi] - x.se.se)); a[x.se.fi].push_back(m_p(cur, 0)); } for (auto x : g[i]) { sum[x.fi] = 0; vis[x.fi] = 0; } } dij(1); if (dist[n] == oo) cout << "-1"; else cout << dist[n]; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void dij(long long int)':
Main.cpp:37:20: warning: iteration 600004 invokes undefined behavior [-Waggressive-loop-optimizations]
   37 |  fo(i,1,N) dist[i] = oo;
      |            ~~~~~~~~^~~~
Main.cpp:7:38: note: within this loop
    7 | #define fo(i, l, r) for(int i = l; i <= r; i++)
......
   37 |  fo(i,1,N) dist[i] = oo;
      |     ~~~~~                             
Main.cpp:37:2: note: in expansion of macro 'fo'
   37 |  fo(i,1,N) dist[i] = oo;
      |  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...