Submission #691264

#TimeUsernameProblemLanguageResultExecution timeMemory
691264Cookie197Robot (JOI21_ho_t4)C++17
0 / 100
306 ms21680 KiB
// Cookie197 // the people who invented competitive programming must be ******* crazy // why am i still here suffering while i can do something else more valuable? // WHY??? #pragma GCC optimize("O4,unroll-loops,no-stack-protector") #pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") #include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<string> #include<iomanip> #include<math.h> #include<unordered_map> #include<numeric> #include<random> using namespace std; #define Why_does_competitive_programming_even_exist ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define pii pair<ll,ll> #define pdd pair<double ,double> #define mp make_pair #define mod 998244353 //#define mod 1000000007 #define endl "\n" #define inf (ll)1e18 #define out(x) cout << #x << " = " << x <<endl; #define out2(a,b) cout<< #a << "[" << b << "]" << " = " << a[b] << endl; #define outp(x) cout << #x << " first = " << x.first << " second = " << x.second << endl int n,m; vector<pii> adj[100005]; ll c[200005], p[200005]; map<pii,int> cnt; map<pii,int> dist; signed main(){ Why_does_competitive_programming_even_exist; cin>>n>>m; for (int i=1;i<=m;i++){ int a,b; cin>>a>>b>>c[i]>>p[i]; adj[a].push_back(mp(b,i)); adj[b].push_back(mp(a,i)); cnt[mp(a,c[i])]++; cnt[mp(b,c[i])]++; } priority_queue<pair<int,pii>,vector<pair<int,pii> >, greater<pair<int,pii> > > pq; pq.push(mp(0,mp(1,0))); while(pq.size()){ int d = pq.top().first, node = pq.top().second.first, color = pq.top().second.second; pq.pop(); if (dist.count(mp(node,color))) continue; //cout<<node<<" "<<color<<" "<<d<<endl; dist[mp(node,color)] = d; for (pii P:adj[node]){ int u = P.first, id = P.second; int count = cnt[mp(node,c[id])]; if (c[id] == color) count--; if (count <= 1) pq.push(mp(d,mp(u,c[id]))); else pq.push(mp(d+1,mp(u,c[id]))); } } int ans = 1e9; for (auto a:dist){ //cout<<a.first.first<<" "<<a.first.second<<" "<<a.second<<endl; if (a.first.first == n) ans = min(ans, a.second); } if (ans == 1e9) cout<<-1<<endl; else cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...